使用 ImageScience 裁剪图像
ImageScience 很酷而且很轻。我在我的 sinatra 应用程序中使用它。但我不明白如何裁剪非方形的图像以及如何制作二维缩略图。
正如我在 ImageScience 网站上发现的那样:
ImageScience.with_image(file) do |img|
img.cropped_thumbnail(100) do |thumb|
thumb.save "#{file}_cropped.png"
end
img.thumbnail(100) do |thumb|
thumb.save "#{file}_thumb.png"
end
img.resize(100, 150) do |img2|
img2.save "#{file}_resize.png"
end
end
我只能使用一个维度来裁剪拇指和调整拇指大小,但我想使用两个维度,就像在 RMagick 中一样。例如,我想从图像中裁剪 100x200px 的框,或者我想制作宽度或高度不大于 300(宽度)或 500(高度)像素的缩略图。
ImageScience is cool and light. I am using it in my sinatra app. But I can't understand how can I crop image with not square form and how can I make thumbnail with two dimensions.
As I found on ImageScience site:
ImageScience.with_image(file) do |img|
img.cropped_thumbnail(100) do |thumb|
thumb.save "#{file}_cropped.png"
end
img.thumbnail(100) do |thumb|
thumb.save "#{file}_thumb.png"
end
img.resize(100, 150) do |img2|
img2.save "#{file}_resize.png"
end
end
I can crop thumb and resize thumb only with ONE dimension but I want to use two, as in RMagick. For example I want to crop 100x200px box from image, or I want to make thumbnail with width or height not bigger then 300 (width) or 500 (height) pixels.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 Devil 代替:
Use Devil instead:
哇,我研究了 ImageScience 来源,发现了很好的方法
with_crop(left, top, right, Bottom)
它帮助我解决了我的问题。http://seattlerb.rubyforge.org/image_science/ImageScience.html
Wow, I've looked into ImageScience sources and found great method
with_crop(left, top, right, bottom)
which helped me with my problem.http://seattlerb.rubyforge.org/image_science/ImageScience.html