Tutorial :How do I auto resize user's inputted images to a specific dimension in PHP?



Question:

When users input their images, their images are any size. I want to be able to resize all the images to a specific dimension. Is there a function that allows me to do that in PHP?

thanks


Solution:1

The function you need is imagecopyresampled, that also interpolate pixels, (imagecopyresized does not);
In my code I use a it in a function like this:

function resizeAndSavePhoto($original, $destination, $dest_width, $dest_height){          $photo = createImage($original);      $size =  getimagesize($original);        $final_photo = imagecreatetruecolor($dest_width, $dest_height);        imagecopyresampled($final_photo, $photo,0,0,0,0,$dest_width, $dest_height, $size[0], $size[1]);      imagejpeg($final_photo, $destination, 100);  }  

$orignal and $destination are filename paths


Solution:2

http://php.net/gd

Specifically, http://php.net/imagecopyresized


Solution:3

Try ImageMagick, it keeps the EXIF information in an image if it needs it, among other things:

http://php.net/manual/en/book.imagick.php


Solution:4

ok you can make something:

http://net.tutsplus.com/tutorials/php/image-resizing-made-easy-with-php/

or use something already made, i use this one:

http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php which works a treat


Solution:5

Here's a very good library that you can resize images with. It has ways to resize them so they are still proportionate and it has options to save, or display images as well. Works really slick

http://phpthumb.gxdlabs.com/


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »