views:

111

answers:

2

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.

+1  A: 

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
banister
I can use ImageMagick, or Rmagick instead. But never heard about Devil. Thanks. I'll look on it
fl00r
@fl00r, Devil is light-weight (like ImageScience). ImageMagick/Rmagick i steer way clear of, they're bulky, slow, hard to install...ugh
banister
Yes. RMagick is real monster. Devil looks feature-enough for me.
fl00r
A: 

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

fl00r