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?
开发者_如何学Gothanks
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
http://php.net/gd
Specifically, http://php.net/imagecopyresized
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
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
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/
精彩评论