I have a Ruby/Rails app and I 'm wondering if there is a way to crop an image starting at the top left point
, and specifyinga width
, height
and the img-url
and get the cropped .jpg
file?
For example, something like:
(x: 0, y: 50, width: 100, height: 200, img-url='http://xxxx', name:'test')
=> result: 'test.jpg'
I'd recommend using rmagick
for that kind of thing. It's the Ruby bindings for ImageMagick, which should have no problem handling the kind of cropping that you're looking for. There are multiple examples here: https://github.com/rmagick/rmagick/blob/master/examples/demo.rb
You'll have to install the ImageMagick package on your web servers, but it's better than trying to roll your own image manipulator. Once you have that up and running you can do something similar to this answer: RMagick: scale and resize image for thumbnail