[SOLVED] Generate Thumbnails on the fly with JPG/GIF files..

Small, short code snippets that other people may find useful. Do you have a good regex that you would like to share? Share it! Even better, the code can be commented on, and improved.

Moderator: General Moderators

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

make sure php_gd2.dll is in the php extensions folder.. I think.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

This is the exact Error Message from IE (IIS6) in a msgbox :

Warning
Unknown():Unable to load dynamic library './php_gd2.dll' - The specified module could not be found

In C:\PHP\dlls php_gd2.dll does not exist but gds32.dll does. Do I have to download php5rc3 ?
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

php_gd2.dll exists in C:\PHP\extensions
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

I had to to set the extension path in php.ini. Its mentioned in php4.3.4 manual that the default is set to C:\PHP\Extension but in my case it wasn't - don't know how because all I did was rename the php.recommended.ini to php.ini.
AimsB
Forum Newbie
Posts: 12
Joined: Thu Jul 08, 2004 9:39 am
Location: UK

Post by AimsB »

Has anyone mentioned the possibility of using ImageMagick? It's a piece of software that needs to be installed on the server, but it comes on servers as standard sometimes now. It handles thumbnails really well but there's also so much you can do with images besides that, like converting the format, rotating it, adding special effects, create animated gifs from a group of images etc etc. Worth looking into I think
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Imagemagick, w00t!?! If you've got imagemagick, in my opinion it's much easier to crop / resize using it as opposed to gd.
Last edited by nigma on Tue Aug 10, 2004 12:17 pm, edited 1 time in total.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

$pic????

Post by neophyte »

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
Correct me if I'm wrong but your first if statement is flawed.

Code: Select all

if(stristr($pic,".jpg"))

$pic is never defined anywhere so all you will get with this script is the error message. If you change $pic to $image_to_convert you will actually get a correct result.

Can you use this script to produce multiple thumbnails of different images on the same page?
leenoble_uk
Forum Contributor
Posts: 108
Joined: Fri May 03, 2002 10:33 am
Location: Cheshire
Contact:

Post by leenoble_uk »

Just to come back to the ratios. I've done this in the past and been annoyed by thin lines at the bottom of images. The problem exists because when you determine the new height using a ration of old width to new width there's every likelihood the number will be a decimal.

An image 50px x 75.86px will then be filled up with the smaller thumnail image only the last line will not be filled properly and you'll end up with whatever the canvas colour is appearing a thin line underneath the picture.

Solution is to round down.

Code: Select all

<?php
$newWidth= 50;

$ratio = $newWidth/$oldWidth;

$newHeight = floor($oldHeight * $ratio);
?>
Post Reply