Orionsbelter Posted February 13, 2010 Share Posted February 13, 2010 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 Quote Link to comment Share on other sites More sharing options...
jl5501 Posted February 13, 2010 Share Posted February 13, 2010 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. Quote Link to comment Share on other sites More sharing options...
Omirion Posted February 13, 2010 Share Posted February 13, 2010 //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. Quote Link to comment Share on other sites More sharing options...
Orionsbelter Posted February 13, 2010 Author Share Posted February 13, 2010 Hi thank you for both replys, Omirion how does that script change the file size lower? or does it not? Once again thank you to you both Quote Link to comment Share on other sites More sharing options...
Omirion Posted February 13, 2010 Share Posted February 13, 2010 Normally it should lower the gif size but by a small amount. Sorry i don't know much about file compression using PHP. Quote Link to comment Share on other sites More sharing options...
Orionsbelter Posted February 13, 2010 Author Share Posted February 13, 2010 Ok thats fine thank you for all your help i will get onto testing this and seeing what else i can do in order to lower the file size. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.