0

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.

fl00r
  • 82,987
  • 33
  • 217
  • 237

2 Answers2

3

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
horseyguy
  • 29,455
  • 20
  • 103
  • 145
  • I can use ImageMagick, or Rmagick instead. But never heard about Devil. Thanks. I'll look on it – fl00r Jun 07 '10 at 13:08
  • @fl00r, Devil is light-weight (like ImageScience). ImageMagick/Rmagick i steer way clear of, they're bulky, slow, hard to install...ugh – horseyguy Jun 07 '10 at 13:22
  • Yes. RMagick is real monster. Devil looks feature-enough for me. – fl00r Jun 07 '10 at 13:38
0

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
  • 82,987
  • 33
  • 217
  • 237