Jump to content

[SOLVED] php getimagesize


The14thGOD

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.