如果图像太小,使用 PHP 调整图像大小

发布于 2024-09-16 07:27:43 字数 139 浏览 4 评论 0原文

我允许用户上传,如果图像太小,我想放大它们(低质量不是问题)。我需要将最小边变为 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

海未深 2024-09-23 07:27:43

正如此处的回答,尝试一下到WideImage

As answered here, give it a try to WideImage.

涫野音 2024-09-23 07:27:43

感谢 Alexander 的 WideImage 建议。

我只是使用了这个:

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

它工作得很好,并且通过使用“向上”选项,它只缩放小于设置尺寸的图像,并保留其他所有内容。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文