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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image Size 1

Status
Not open for further replies.

Mighty

Programmer
Feb 22, 2001
1,682
US
Hi folks,

Is there any way to change the size of an image dynamically using PHP. Basically I want to have one image uploaded to my site but be able to dynamically resize it to display it as a thumbnail. Is that possible with PHP?

Mighty
 
That looks like it has potential. Thanks for the tip.

Mighty
 
I think this one is what you where looking for:

There is an example there of how to generate an image, only half size of original.

You can however make it generate a STATIC size of the copied image.

You do not have to STORE the image, as you can display it and then delete the temp image after it's shown to the user.

What is best to do? This depends on several factors:
* Number of visitors on your pages
* Number of hits on your pages
* How lager images you think is o.k. for bandwidth
* Your bandwidth quota
* Your HD quota

I however do not think that the sitepoint tutorial was worth any pennies or cents, as it simply adds the 'width="x" height="y"' to the <img> tag.

That is not resizing at all, and it will force the download of the original image. (it will look resized, but it's actually fullsized, almost like zoom-out).

eg. If you have some page with only one image per item, this might be interesting.. If however, you wish to show a thumb-list in a gallery, I would not do it like that, as then the images will take a considerate time to load.

I think this matter is not most of hd-space, but of bw-usage, and therefore I think it's best to generate TN_ files for each image.

You can use one file for showing images or TN_ and simply switch a function-variable.

Inside that function variable, you must remember to check if image excist.

/* here you would switch the action-variable and then retrieve either thumb or fullsize */

if (!is_file("TN_" . $image)) {
if (is_file($image)) {
createThumb($image, "TN_".$image);
}
else {
echo "404"
}
}
ps. this is psuedocode, do not take it as it is, as it would need some optimalization.



Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top