php:创建自定义大小的缩略图
我熟悉使用 imagecopyresampled 在 php 下调整图像大小和裁剪图像,但现在我遇到了一个特殊问题: 该任务是从例如裁剪大图像。 1600x1200 至 500x120,这意味着将大小调整为 500 像素,并将其高度裁剪为 120 像素。有没有一些简单的方法或者我需要自己计算裁剪值?谢谢
i'm familiar with resizing and cropping images under php using imagecopyresampled but now i'm having a special problem:
the task is cropping a large image from eg. 1600x1200 to 500x120, which means resizing down to 500px and crop its height that it'S 120px. is there some easy way or do i need to calculate the cropping values all on my own? thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个名为 PHPThumb 的 PHP 库可以帮助您。您可以在这里找到 https://github.com/masterexploder/PHPThumb
他们有一个自适应调整大小方法,可以你在寻找什么。 https://github.com/masterexploder/PHPThumb/wiki/Basic-Usage
There is PHP library that could help you out called PHPThumb. You can find here https://github.com/masterexploder/PHPThumb
They have an adaptive resize method that does what you're looking for. https://github.com/masterexploder/PHPThumb/wiki/Basic-Usage
你必须自己做。
我不知道你是否想要裁剪,所以这里是如何计算两者的值:
缩放图像:调整大小以适应新的 wxh 保持纵横比(因此 1 条边可能短于指定)
调整大小和裁剪:如果新的宽高比不同,则调整图像大小并裁剪它以适合指定的宽x高(例如,如果宽高比不同,图像将调整大小以匹配短尺寸上的指定尺寸)以及较长的尺寸,如果中间被剪掉了)
You have to do it yourself.
I don't know if you want to crop or not, so here's how to calculate the values for both:
Scale image: resize to fit within new w x h keeping aspect ratio (so 1 side may be shorter than specified)
Resize and Crop: Resizes image and crops it to fit into the specified w x h if new aspect ratio is different (e.g. if aspect ratios are different, image will be resized to match specified size on the short size and the longer size if cropped in the middle)