Cropping image with ImageScience
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
精彩评论