使用 ImageScience 裁剪图像

发布于 2024-09-04 16:06:50 字数 622 浏览 1 评论 0原文

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 技术交流群。

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

发布评论

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

评论(2

紫罗兰の梦幻 2024-09-11 16:06:50

使用 Devil 代替:

Devil.with_image("horse.png") do |img|
    img.crop(0, 0, 100, 100)
    img.resize2(500, 500)
    img.save("horse_resized.jpg", :quality => 85)
end

Use Devil instead:

Devil.with_image("horse.png") do |img|
    img.crop(0, 0, 100, 100)
    img.resize2(500, 500)
    img.save("horse_resized.jpg", :quality => 85)
end
紫﹏色ふ单纯 2024-09-11 16:06:50

哇,我研究了 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

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