[SOLVED] Generate Thumbnails on the fly with JPG/GIF files..
Moderator: General Moderators
[SOLVED] Generate Thumbnails on the fly with JPG/GIF files..
deicded to remove this.
Last edited by infolock on Tue Sep 06, 2005 3:54 pm, edited 3 times in total.
What if someone use it like
<img src="resize_image.php?image_to_convert=http://www.google.com/">
? Have you tested this snippet against traversal+possible buffer overflow in GD ?
I'm a paranoic, indeed
<img src="resize_image.php?image_to_convert=http://www.google.com/">
? Have you tested this snippet against traversal+possible buffer overflow in GD ?
I'm a paranoic, indeed
If you wish to have it actually resize, instead of to a default 50x50, replace the $height = 50; with:
or, with width:
Code: Select all
$width = 50;
$height = round($current_image_height / ($current_image_width / $resize_width))Code: Select all
$height = 50;
$width = round($current_image_width / ($current_image_height / $height))Using this snippet
I have tried this snippet on my server and I get a blue image with error on it, could you tell me what I am doing wrong?
Thank you,
Stephanie
Thank you,
Stephanie
Your code is a bit off... You should get a ratio of w/h for both your maximum dimensions, and the image in question. If the ratio of your max thumbnail is bigger than that of the image, you need to find out the new width of the thumbnail-to-be. Once you know the ratio and which dimension you need to match, you already have the formula to convert.
The trick with images is to work on ratios of w/h, as opposed to individual dimensions. If you adhere to the ratios, your images never look screwy, which is nice
If
ratio = w / h
then a new width for a thumbnail with a max. height of 100 is
w = ratio * h
where h = 100
That method means you get images with the correct aspect ratio, which is ESSENTIAL for photographs. You should also use imagecopyresampled for best results.
Another good idea is to cut down on GD processing. This can be easily achieved by caching the output. Take the image's filename and filemtime, and incorporate those into a filename in a suitable location. Upon invoking the image-resizing script, check to see if the thumbnail exists, and if present output it. If not, run the resize script and save the thumbnail in that location.
The trick with images is to work on ratios of w/h, as opposed to individual dimensions. If you adhere to the ratios, your images never look screwy, which is nice
If
ratio = w / h
then a new width for a thumbnail with a max. height of 100 is
w = ratio * h
where h = 100
That method means you get images with the correct aspect ratio, which is ESSENTIAL for photographs. You should also use imagecopyresampled for best results.
Another good idea is to cut down on GD processing. This can be easily achieved by caching the output. Take the image's filename and filemtime, and incorporate those into a filename in a suitable location. Upon invoking the image-resizing script, check to see if the thumbnail exists, and if present output it. If not, run the resize script and save the thumbnail in that location.
I ended up using: http://phpthumb.sourceforge.net/
Image Functions in localhost
For these image functions, all works ok in my site but not on my localhost. Is there anyway to get this worked in localhost ?
Localhost : php 4.3.4
My Website : php 4.3.4
I did not manually install gd since it was mentioned in php.net that 4.3 and up comes with gd intalled.
On my localhost a similar problem is there when including files with parameters - include("a.php?arg1=x&arg2=y");
So basically its the same thing - does not accept arguments on localhost.
Thanks
My Website : php 4.3.4
I did not manually install gd since it was mentioned in php.net that 4.3 and up comes with gd intalled.
On my localhost a similar problem is there when including files with parameters - include("a.php?arg1=x&arg2=y");
So basically its the same thing - does not accept arguments on localhost.
Thanks
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
you still need to tell it to load the module.. look in your php.ini for or similar... (assuming a windows machine)
Code: Select all
;extension=php_gd2.dll