You can use RMagick on the server-side. You'll need to
> gem install rmagick
Or use whatever package manager you have. Once it's installed you should be able
to run the following:
require 'RMagick'
def cropImage(input_filename)
original = Magick::ImageList.new(filename)
# NorthEast says take from the top, right, corner. Start
# at 20,20 and make the final image 20x20.
crop = original.crop(NorthEast, 20,20,20,20)
output_filename = "cropped-foo.jpg"
crop.write(output_filename)
return output_filename
end
This will show only the top-right corner of an image.
If you want to crop you'll need to get the linked-to image, however you'd like. Perhaps using Net::HTTP, (or from your DB, it's unclear to me from your post)
Net::HTTP.start("EXAMPLE.COM") { |http|
resp = http.get("/path/to/X.jpg")
open("orig.jpg", "wb") do |file|
file.write(resp.body)
end
cropped_filename = cropImage("orig.jpg")
#put the resulting file in some location where
#you can get to it and add that link to your
#template.
end