The14thGOD Posted February 7, 2008 Share Posted February 7, 2008 I'm troubleshooting a website and I was wondering if I did this wrong: <?php $size = getimagesize($row['image']); $width = $size[0]; $height = $size[1]; echo"<img src=\"$row[image]\" width=\"$width\" height=\"$height\" />"; ?> the image path is stored in a database. The problem is that unless you are viewing in firefox you don't see the images and even in some versions of firefox it wont show the images because in the source it's : width="" height="". Thanks for any help. Justin Link to comment https://forums.phpfreaks.com/topic/89916-solved-php-getimagesize/ Share on other sites More sharing options...
phpSensei Posted February 7, 2008 Share Posted February 7, 2008 its More like list($width, $height) = getimagesize("img/flag.jpg"); So Try This <?php list($width, $height) = getimagesize($row['image']); echo"<img src=\"$row[image]\" width=\"$width\" height=\"$height\" />"; ?> Link to comment https://forums.phpfreaks.com/topic/89916-solved-php-getimagesize/#findComment-460944 Share on other sites More sharing options...
The Little Guy Posted February 7, 2008 Share Posted February 7, 2008 did you store the image in the database? or a link to the image? Link to comment https://forums.phpfreaks.com/topic/89916-solved-php-getimagesize/#findComment-460945 Share on other sites More sharing options...
phpSensei Posted February 7, 2008 Share Posted February 7, 2008 edit: If it isnt in your db then just link the image to the root folder, and make sure for $row['image'] you have is "folder/image.png" else use list($width, $height) = getimagesize("image_folder/".$row['image']); Link to comment https://forums.phpfreaks.com/topic/89916-solved-php-getimagesize/#findComment-460946 Share on other sites More sharing options...
phpSensei Posted February 7, 2008 Share Posted February 7, 2008 edit: Sorry I thought i was editing my post, but here http://ca3.php.net/manual/en/function.getimagesize.php Link to comment https://forums.phpfreaks.com/topic/89916-solved-php-getimagesize/#findComment-460949 Share on other sites More sharing options...
craygo Posted February 7, 2008 Share Posted February 7, 2008 why bother putting in the width and height. by omitting the width and height the web browser will automatically use the image's width and height. You only need to use width and height if you are going to make the image bigger or smaller. Ray Link to comment https://forums.phpfreaks.com/topic/89916-solved-php-getimagesize/#findComment-460953 Share on other sites More sharing options...
phpSensei Posted February 7, 2008 Share Posted February 7, 2008 why bother putting in the width and height. by omitting the width and height the web browser will automatically use the image's width and height. You only need to use width and height if you are going to make the image bigger or smaller. Ray While this is true, if he needs to resize the images if it is too large for the screen, or web page, then you can use these vars with if and else to resize the image to a default size, if it exceeds a certan number of width or height. Link to comment https://forums.phpfreaks.com/topic/89916-solved-php-getimagesize/#findComment-460956 Share on other sites More sharing options...
phpSensei Posted February 7, 2008 Share Posted February 7, 2008 edit: nvm Link to comment https://forums.phpfreaks.com/topic/89916-solved-php-getimagesize/#findComment-460959 Share on other sites More sharing options...
The Little Guy Posted February 7, 2008 Share Posted February 7, 2008 if you are saving the image in a database, then you need to make a php file to create the file to make output, then you can use: <img src="createMyImage.php?imageID=233" /> to display the image Link to comment https://forums.phpfreaks.com/topic/89916-solved-php-getimagesize/#findComment-460961 Share on other sites More sharing options...
craygo Posted February 7, 2008 Share Posted February 7, 2008 Yes sensei you are correct. But he has not said he wanted to resize it. I just wanted to make sure he understood that. and getimagesize also has a nice little function in the third part of the array. It will return the width and height in a browser friendly format. <?php $imagename = "images/test.jpg"; $size = getimagesize($imagename); $dims = $size[3]; echo"<img src=\"$row[image]\" $dims />"; // $dims will contain width="xxx" height="xxx" ?> no need to get the width and height separate unless you will be resizing it as Sensei stated above. Ray Link to comment https://forums.phpfreaks.com/topic/89916-solved-php-getimagesize/#findComment-460970 Share on other sites More sharing options...
The14thGOD Posted February 7, 2008 Author Share Posted February 7, 2008 Thanks for the help guys. I tried the <?php list($width, $height) = getimagesize($row['image']); echo"<img src=\"$row[image]\" width=\"$width\" height=\"$height\" />"; ?> method but that didn't work either. I am storing the image path in the database. The reason why I want the width and height of the image is because it generally is bad to not include it so that way when the user is scrolling through the content when images load it doesn't throw them off or jump them a little bit. Currently I am in a position where I can't try the other methods that you have posted (in class to be specific and the files are at home). Thank you again for your help. I will post if I have more problems. Justin Link to comment https://forums.phpfreaks.com/topic/89916-solved-php-getimagesize/#findComment-461128 Share on other sites More sharing options...
phpSensei Posted February 7, 2008 Share Posted February 7, 2008 Whats the value of $row['image'] ? Link to comment https://forums.phpfreaks.com/topic/89916-solved-php-getimagesize/#findComment-461150 Share on other sites More sharing options...
The14thGOD Posted February 7, 2008 Author Share Posted February 7, 2008 The dims feature worked. Thank you all for the help Link to comment https://forums.phpfreaks.com/topic/89916-solved-php-getimagesize/#findComment-461341 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.