如果图像太小,请使用PHP调整图像大小 [英] Resize image using PHP if it's too small

查看:143
本文介绍了如果图像太小,请使用PHP调整图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我允许用户上传,如果图片太小(我们的图片质量太低,我想要缩放图像)。我需要使最小的一面变为150px,并将另一个尺寸放大以保持纵横比。我需要让它适用于.jpg,.gif和.png文件。

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.

推荐答案

感谢Alexander提出的WideImage建议。

Thanks to Alexander for the WideImage suggestion.

我只是使用了这个:

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.

这篇关于如果图像太小,请使用PHP调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆