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 Quote Link to comment 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\" />"; ?> Quote Link to comment 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? Quote Link to comment 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']); Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 7, 2008 Share Posted February 7, 2008 edit: nvm Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 7, 2008 Share Posted February 7, 2008 Whats the value of $row['image'] ? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.