View Full Version : Change image filesize and sizes, gd

07-09-2003, 10:55 AM
How can I change the filesize and sizes of an image which will be created off an uploaded file? Basically trying to create thumbnails which won't take a long time to load and use up so much bandwidth. No idea if this is the right way to give you info of my gd or not http://www.phathosting.co.uk/gd.php

07-09-2003, 12:04 PM
Well I used to have a script like that but I believe it was in Perl and I can't find it anymore.

I think you should do it like this:

Create a GD-image from the uploaded file
something like this: GD->createNewImageFromFile("uploaded.jpg")
create another (blank) GD-image

check the size of the image like this:
oldW = orgImageW;
oldH = orgImageH;
maxW = 200;
maxH = 150;

if(oldW>maxW) {
tempVar = oldW/maxW;
newW = oldW/tempVar;
newH = oldH/tempVar;
if(oldH>maxH) {
tempVar = oldH/maxH;
newW = oldW/tempVar;
newH = oldH/tempVar;
use the CopyResized-option or something to copy the uploaded image to the blank one (resized)

I hope this helps you (a little)

Laetherzz, Chris

07-09-2003, 07:18 PM
To get the compression to assure a certain filesize you would need to recurse
, then read filesize('path/name.jpg') and keep reassigning $compression until you meet the filesize limitations.

Eg - start at maybe 85 quality - save, filesize test - then determine if the file is too big or small - resave if needed

07-09-2003, 10:37 PM
Ta, I'll see what I come up with :)