开发者

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

开发者 https://www.devze.com 2022-12-24 12:14 出处:网络
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?

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?

开发者_如何学Go

thanks


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消