Jump to content

creating thumbnail images and low size images


Orionsbelter

Recommended Posts

Ok so i am a newbie to PHP and need a bot of help. I have created a script for uploading an image to my website, this works just fine. However i now wish to add to the script a part which will make an thumbnail image of a certain size lets so 200 width by 200 height. I also want it to keep the image as good quality as i can so i wish to lower the size of the files lets so it was 100kb maybe lower it to 10kb.

 

I have googled this for hours and have found some example but all are too confusing. Also i should state the images will either be a GIF, JPG or PNG.

 

Thank you for reading an any help what so ever will be very grateful

Link to comment
Share on other sites

Your best approach to doing this is phpthumb http://phpthumb.sourceforge.net/ with which, you can either produce your thumbnail on demand, or create a thumbnail and save it as a file.

 

You can of course write the code yourself, using the extensive image functions of php, but you may find the learning curve a bit steep.

Link to comment
Share on other sites

//Get width and height of input gif . Size[0] = width , Size[1]= height
$size = GetImageSize("some.gif") 

//Input gif , the large pic
$im_in = ImageCreateFromGif("some.gif"); 

// Output gif , The thumbnail
$im_out = Imagecreate(200,200); // Imagecreate(width,height); 

//Copy input image into output image and rezise it.
ImageCopyResized ($im_in , $im_out , 0,0,0,0, $size[0], $size[1],200, 200 , ); 

/* ImageCopyResized prototype:
ImageCopyResized(input,output,input-x,input-y,output-x, output-y,input-width,input-height,output-width, output-height)
*/

imagegif($im_out, "small_some.gif"); // save small gif

//Destroy the created instances
imagedestroy($im_in);
imagedestroy($im_out);

 

You now should have a image named small_some.gif that is re-sized to your specification.

 

Just one note, you need to have the GD library compiled with your PHP. It is compiled by default i think since PHP 4 i think. But is turned of by default. Check you php.in and uncomment where it says something like gd2.dll if on windows that is.

 

Hope this helps to some extent, tinker around with the script see if you can get it to work for you.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.