开发者

Resize image using PHP if it's too small

开发者 https://www.devze.com 2023-01-14 03:05 出处:网络
I\'m allowing user uploads, and I want to scale their images开发者_运维知识库 up if they\'re too small (low quality is a non-issue). I need to make the smallest side become 150px and have the other di

I'm allowing user uploads, and I want to scale their images开发者_运维知识库 up if they're too small (low quality is a non-issue). I need to make the smallest side become 150px and have the other dimension scale up to keep the aspect ratio. I need to make it work for .jpg, .gif and .png files.

Any pointers would be greatly appreciated, I'm struggling to find anything about making images larger like this.


As answered here, give it a try to WideImage.


Thanks to Alexander for the WideImage suggestion.

I simply used this:

require_once('WideImage/WideImage.php');
$image = WideImage::load($_FILES['image']['tmp_name']);
$resized = $image->resize(150,150,'outside','up');
$resized->saveToFile($target_file);

It worked perfectly, and by using the "up" option, it only scales images smaller than the dimensions set up, and leaves everything else.

0

精彩评论

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