kurt.santo Posted May 15, 2008 Share Posted May 15, 2008 I finally found a function, which will help me display image data of any kind and any size. The following: list($width, $height, $type, $attr) = getimagesize("$IMAGE_BASE_PATH$id.gif");echo "<img src=\"$IMAGE_BASE_PATH$id.gif\" width=\"$width\" height=\"$height\" alt='getimagesize() example' />"; should have displayed the width and height values. Instead it renders an empty page. When I take the width and height bit out of <img /> the image displays. I also saw example as width=\"{$width}\" (height accordingly). Also does not work:-( Where am I going wrong here?Kurt Link to comment Share on other sites More sharing options...
justsomeguy Posted May 15, 2008 Share Posted May 15, 2008 If you're trying to replace 2 variables in a row like that they should be in brackets.{$IMAGE_BASE_PATH}{$id} Link to comment Share on other sites More sharing options...
jeffman Posted May 15, 2008 Share Posted May 15, 2008 I assume $IMAGE_BASE_PATH is your own constant? Are you sure it ends with a slash? Link to comment Share on other sites More sharing options...
zppblood Posted May 15, 2008 Share Posted May 15, 2008 I assume $IMAGE_BASE_PATH is your own constant? Are you sure it ends with a slash?Variables start with $ and constants have to start with a letter or _ using define(). Link to comment Share on other sites More sharing options...
jeffman Posted May 15, 2008 Share Posted May 15, 2008 So I'm loose with my language in a trivial context. Does $IMAGE_BASE_PATH end with a slash? Link to comment Share on other sites More sharing options...
zppblood Posted May 16, 2008 Share Posted May 16, 2008 So I'm loose with my language in a trivial context. Does $IMAGE_BASE_PATH end with a slash? I'm the same way, just wanted to make sure you didn't confuse the two. Link to comment Share on other sites More sharing options...
kurt.santo Posted May 16, 2008 Author Share Posted May 16, 2008 Sorry, guys. When you are still in full bloom I am tired and have to go to bed (24.00 last night);-) Live since a while in UK now...Changed it to: list($width, $height, $type, $attr) = getimagesize("$IMAGE_BASE_PATH$id.gif");echo "<img src=\"{$IMAGE_BASE_PATH}{$id}.gif\" width=\"$width\" height=\"$height\" alt='getimagesize() example' />"; but still the same problem. Only when I take out the bit with width and height the image displays...And to lift the secret with $IMAGE_BASE_PATH it have it at the top as:$IMAGE_BASE_PATH = "http://www.domain.co.uk/data/images/"; So, there is a slash:-)Any ideas?Kurt Link to comment Share on other sites More sharing options...
Wander Posted May 16, 2008 Share Posted May 16, 2008 are you sure the file exists?because this works fine for me: $IMAGE_BASE_PATH = 'http://php.net/images/';$id = 'php';list($width,$height) = getimagesize("$IMAGE_BASE_PATH$id.gif");echo "<img src=\"$IMAGE_BASE_PATH$id.gif\" width=\"$width\" height=\"$height\" alt='getimagesize() example' />"; Link to comment Share on other sites More sharing options...
jeffman Posted May 16, 2008 Share Posted May 16, 2008 Kurt, you're veruckt. I've tried your code 15 different ways, and I get 100% with all of them, including the original.I assume you've done a view source to see what's actually being printed and if it tallies with the facts? Link to comment Share on other sites More sharing options...
kurt.santo Posted May 16, 2008 Author Share Posted May 16, 2008 Kurt, you're veruckt. I've tried your code 15 different ways, and I get 100% with all of them, including the original.I assume you've done a view source to see what's actually being printed and if it tallies with the facts?Yes, I did it all. I even tried with the picture hardcoded into $IMAGE_BASE_PATH. The source code shows:<img src="http://www.mydomain.co.uk/data/images/c.gif" width="" height="" alt='getimagesize() example' />with the complete file being:<?php $IMAGE_BASE_PATH = "http://www.mydomain.co.uk/data/images/"; $THUMB_BASE_PATH = "http://www.mydomain/data/images/thumbs/";$id = (isset($_GET['id']) ? $_GET['id'] : c);?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Image display</title></head><body><ul><li><a href="displayImages.php?id=a">Image a</a></li><li><a href="displayImages.php?id=b">Image b</a></li></ul><?phplist($width, $height, $type, $attr) = getimagesize("$IMAGE_BASE_PATH$id.gif");echo "<img src=\"{$IMAGE_BASE_PATH}{$id}.gif\" width=\"$width\" height=\"$height\" alt='getimagesize() example' />"; ?></body></html> When I just echoecho "<img src=\"{$IMAGE_BASE_PATH}{$id}.gif\" alt='getimagesize() example' />";it shows correctly with source code as:<img src="http://www.mydomain.co.uk/data/images/c.gif" alt='getimagesize() example' />Is there anything I need to enable to use the function? Am really lost on this one...Kurt Link to comment Share on other sites More sharing options...
Wander Posted May 16, 2008 Share Posted May 16, 2008 what do u see when u useprint_r(getimagesize("$IMAGE_BASE_PATH$id.gif"));can copy the output of that here?and do you have error_reporting at E_ALL? Link to comment Share on other sites More sharing options...
kurt.santo Posted May 16, 2008 Author Share Posted May 16, 2008 what do u see when u useprint_r(getimagesize("$IMAGE_BASE_PATH$id.gif"));can copy the output of that here?and do you have error_reporting at E_ALL?I started script as:error_reporting (E_ALL);and used nowprint_r(getimagesize("$IMAGE_BASE_PATH$id.gif"));Still no sign of pic. Source code shows:<img src="http://www.mydomain.co.uk/data/images/c.gif" width="" height="" alt='getimagesize() example' /></body>I really do not get it...Kurt Link to comment Share on other sites More sharing options...
Wander Posted May 16, 2008 Share Posted May 16, 2008 u used print_r, does that show anything in the source code? it should, can u copy that here? it should give some "array(...stuf...)" in the source Link to comment Share on other sites More sharing options...
kurt.santo Posted May 16, 2008 Author Share Posted May 16, 2008 u used print_r, does that show anything in the source code? it should, can u copy that here? it should give some "array(...stuf...)" in the sourceNo, that is the funny thing. It does not show a thing. The source code of the file is (and nothing else):<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Image display</title></head><body><ul><li><a href="displayImages.php?id=a">Image a</a></li><li><a href="displayImages.php?id=b">Image b</a></li></ul><img src="http://www.mydomain.co.uk/data/images/c.gif" width="" height="" alt='getimagesize() example' /></body></html> Kurt Link to comment Share on other sites More sharing options...
kurt.santo Posted May 16, 2008 Author Share Posted May 16, 2008 Another point to mention: When I just have it as: <?phplist($width, $height, $type, $attr) = getimagesize("images/a.gif");echo "<img src=\"images/a.gif\" width=\"$width\" height=\"$height\" alt=\"getimagesize() example\" />";?> it works. I really do not understand why the other one does not work, especially when I take the height and width bit out, it displays without a fault (although it does not show width and height). Strange it does not do the print_r...Kurt Link to comment Share on other sites More sharing options...
Wander Posted May 17, 2008 Share Posted May 17, 2008 is it possible that it doesnt reach that point? is it in some if-statement? are you sure you edit the same file as the file you see in ure browser? (its possible that your accidently editting a backup file or copy instead?)try make a new file and dont do much other stuff around it, justprint_r(getimagesize("some example picture"));to see if that works Link to comment Share on other sites More sharing options...
kurt.santo Posted May 17, 2008 Author Share Posted May 17, 2008 is it possible that it doesnt reach that point? is it in some if-statement? are you sure you edit the same file as the file you see in ure browser? (its possible that your accidently editting a backup file or copy instead?)try make a new file and dont do much other stuff around it, justprint_r(getimagesize("some example picture"));to see if that worksThis seems to work. It prints:Array ( [0] => 650 [1] => 650 [2] => 1 [3] => width="650" height="650" [bits] => 8 [channels] => 3 [mime] => image/gif ) I really do not get this one. There is no if statement at all in file and I do not think I edit a different file. I include the whole code below:<?php error_reporting (E_ALL);$IMAGE_BASE_PATH = "http://www.mydomain.co.uk/data/images/"; $THUMB_BASE_PATH = "http://www.mydomain.co.uk/data/images/thumbs/";$id = (isset($_GET['id']) ? $_GET['id'] : c);?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Image display</title></head><body><ul><li><a href="displayImages.php?id=a">Image a</a></li><li><a href="displayImages.php?id=b">Image b</a></li></ul><?phplist($width, $height, $type, $attr) = getimagesize("$IMAGE_BASE_PATH$id.gif");echo "<img src=\"{$IMAGE_BASE_PATH}{$id}.gif\" width=\"$width\" height=\"$height\" alt='getimagesize() example' />";print_r(getimagesize("$IMAGE_BASE_PATH$id.gif")); ?></body></html> Do you have any ideas?Kurt Link to comment Share on other sites More sharing options...
boen_robot Posted May 18, 2008 Share Posted May 18, 2008 The ternary operator is practically an if statement. Look at where you get your $id: $id = (isset($_GET['id']) ? $_GET['id'] : c); This is actually pretty wrong btw.It says that if there is an "id" query string variable, use its value directly, otherwise, use the value of a constant named "c". Since there's no such constant, PHP uses the value "c" instead.If you really meant the value "c", you should enclose it in quotes. In addition, you should make sure that $_GET['id'] has an acceptable value at all times. If it's an integer, the easiest thing you may do is cast it as such.eg. $id = (isset($_GET['id']) ? (int) $_GET['id'] : 'c'); Link to comment Share on other sites More sharing options...
kurt.santo Posted May 19, 2008 Author Share Posted May 19, 2008 boen_robot,Thanks for you input. I actually meant the value, so I enclosed it in parentheses. Still, it did not solve my problem. Now I simplified the file to its bare minumum and still not working. The basic files is: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Image display</title></head><body><h1>Just a test</h1><?php$id = "c";$IMAGE_BASE_PATH = "http://www.mydomain.co.uk/data/images/"; list($width, $height, $type, $attr) = getimagesize("{$IMAGE_BASE_PATH}{$id}.gif");echo "<img src=\"{$IMAGE_BASE_PATH}{$id}.gif\" width=\"$width\" height=\"$height\" alt=\"test\" />";print_r(getimagesize("{$IMAGE_BASE_PATH}{$id}.gif")); ?></body></html> And the image tag still shows without the values for width and height (so pic is also not showing on page:<img src="http://www.mydomain.co.uk/data/images/c.gif" width="" height="" alt="test" />I cannot understand what is going wrong here...KurtPS the print_r does also not bring up anyting... Link to comment Share on other sites More sharing options...
Wander Posted May 19, 2008 Share Posted May 19, 2008 copy the url the source of the page gives to the address bar, are you sure the image file exists? Link to comment Share on other sites More sharing options...
jeffman Posted May 19, 2008 Share Posted May 19, 2008 Maybe try, as a more complicated alternative: $im = imagecreatefromgif ("{$IMAGE_BASE_PATH}{$id}.gif");$width = imagesx ($im);$height = imagesy ($im);imagedestroy ($im);echo "Image resource = $im<br>width = $width<br>height = $height"; Link to comment Share on other sites More sharing options...
kurt.santo Posted May 23, 2008 Author Share Posted May 23, 2008 Maybe try, as a more complicated alternative:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Image display</title></head><body><ul><li><a href="imgAttr2.php?id=a">Image a</a></li><li><a href="imgAttr2.php?id=b">Image b</a></li></ul>Image resource = <br>width = <br>height = </body></html> Am really lost as it seems to work for anybody else...Kurt Link to comment Share on other sites More sharing options...
jeffman Posted May 23, 2008 Share Posted May 23, 2008 Kurt, by now this seems stoopid, BUT -- would you run phpinfo() just to see if the GD image library is even installed? I can't imagine you wouldn't be getting errors every time you called a non-existent function, but we must dot our i's and cross our t's, you know?The thing is, unless I remember incorrectly, you haven't gotten a positive result from any image function. Could be there's a BIG problem? Link to comment Share on other sites More sharing options...
Wander Posted May 23, 2008 Share Posted May 23, 2008 http://php.net/getimagesizeNote: The getimagesize() function does not require the GD image library.but i agree its weird theres no positive result yet, kurt, are you completely sure the image exists? ure not mistyping something? (case sensitive) Link to comment Share on other sites More sharing options...
kurt.santo Posted May 23, 2008 Author Share Posted May 23, 2008 GD is installed as:GD Support enabled GD Version bundled (2.0.34 compatible) Also, before I go crazy in the coconut I have made the file as simple as possible. It reads now: <?php error_reporting (E_ALL);?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Image display</title></head><body><?phplist($width, $height, $type, $attr) = getimagesize("images\a.gif");echo "<img src=\"images\a.gif\" width=\"$width\" height=\"$height\" alt='getimagesize() example' />";print_r(getimagesize("a.gif")); ?></body></html> The source code shows now: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Image display</title></head><body><img src="images\a.gif" width="" height="" alt='getimagesize() example' />Array( [0] => 650 [1] => 650 [2] => 1 [3] => width="650" height="650" [bits] => 8 [channels] => 3 [mime] => image/gif)</body></html> ??? Do not get it...Kurt Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.