开发者

Cropping image with ImageScience

开发者 https://www.devze.com 2023-01-02 06:28 出处:网络
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.

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开发者_StackOverflow中文版(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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号