Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image properties 1

Status
Not open for further replies.

degroat

Programmer
Sep 15, 2003
58
US
Is there a way in PHP (or Javascript, I guess) to determine the size of a graphic and then set the size depending on what the function returns?

These images are not in a DB... so what I need to do is load it up in a page just like any other image, and then if the image is larger than a certain size, I need to restrict the size.
 
you can actually do this by just using normal html.

if you want the image to be a certain width, just create the width tag,
the heigh should auto adjust to keep the image in perspective,

Same goes for the height tag... if you add one of them the other will auto resize to match the chosen size.

thanks
 
I can't do that because I don't want to make images larger than their actual size.... so if an item has a width 20px less than my max width, I want it to stay that size. But, if an image is 20px over my max width, then I want to decrease the size.
 
That's exactly what I was looking for.. thanks sleipnir.
 
Is there a function to determine whether or not an image exists? Using the function suggested above throws a warning if an image can't be found which throws the page off... plus, I'd like to know if an image doesn't exist since I couldn't possibly check to make sure there are both a thumb and a full size jpeg for all 95,000 items in the DB.
 
You have to use file_exists() in order to determine whether a file exists on the filesystem.

So something like:

if (file_exists($filename))
{
$image_data = getimagesize($filename);
}
else
{
$image_data = FALSE;
}

should prevent the error and give you something to test $image_data against later in your code.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top