Resize image using PHP if it's too small

喜你入骨 提交于 2019-12-12 19:58:43

问题


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.


回答1:


As answered here, give it a try to WideImage.




回答2:


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.



来源:https://stackoverflow.com/questions/3595661/resize-image-using-php-if-its-too-small

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!