RMagick:缩放图像并调整缩略图大小
我想调整/缩放图像。原件的尺寸与 300x200 或 512x600 不同。我想将图像大小调整为 100x100,但不要裁剪图像中的任何内容或更改比例。理想情况下,图像首先将长边缩放至 100(纵横比),然后用白色填充较小的边缘。
.---------.
|- - - - -|
| IMAGE |
|- - - - -|
'---------'
我不使用 Paperclip 或 Rails,只使用 RMagick。
I want to resize/scale an image. The originals have not the same dimensions like 300x200 or 512x600. I want to resize the image to 100x100 but DONT crop anything from the image or change ratio. Ideally the image will be first scale the long edge to 100 (aspect ratio) and then fill up the smaller edge with white.
.---------.
|- - - - -|
| IMAGE |
|- - - - -|
'---------'
I dont use Paperclip or Rails, just RMagick.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我通过将调整大小的图像与新的 100x100 图像合并来完成此操作。这肯定不是最好的方法,但它有效:
I've done it with merging the resized image with a new 100x100 image. That's for sure not the best way but it works:
玩了一段时间后,我得到了 Fu86 的复合技巧,如下所示:
AtopCompositeOp
似乎比CopyCompositeOp
效果更好,后者由于某种原因将我的部分背景变成了黑色。After playing with it for a while I got Fu86's composite trick to work like so:
AtopCompositeOp
seems to work better thanCopyCompositeOp
, which turned part of my background black for some reason.注意:在heroku上,截至本文发布时,它使用imagemagick 6.5.7-8,我需要将x和y翻译乘以-1(并发送正数)。版本 6.8.0-10 需要负数。
Note: on heroku, which as of this posting uses imagemagick 6.5.7-8, I needed to multiply the x and y translations by -1 (and send positive numbers). Version 6.8.0-10 expects negative numbers.
看来你想使用 change_geometry...
It seems you want to use change_geometry...