Forum: Ruby on Rails file_column Cropping -> image offset information

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
234baba7870c09d73a2805438a75d36d?d=identicon&s=25 Martijn van Leeuwen (Guest)
on 2006-03-08 12:36
(Received via mailing list)
Hello,

I had a problem cropping images with file_column. These are my settings:

file_column :image, :magick => {
        :versions => {
            :thumb => "80x80>",
            :medium => "150x150>",
            :square => {
                :crop => "1:1",
                :size => "50x50!"
            }
        },
        :geometry => "400x300>"
    }

With a square thumbnail i had the following problem; the offset
information of the images wasn't reset. The i found this in the rmagick
documentation:

http://redux.imagemagick.org/RMagick/doc/image1.ht...
--------------------------------------------------------------------------

The |crop| method retains the offset information in the cropped image.
This may cause the image to appear to be surrounded by blank or black
space when viewed with an external viewer. This only occurs when the
image is saved in a format (such as GIF) that saves offset information.
To reset the offset data, add |true| as the last argument to |crop|. For
example,

cropped = img.crop(x, y, width, height, true)

You can add |true| as the last argument with any of the three argument
list formats described above.

--------------------------------------------------------------------------

so adding ',true' in the file magick_file_column.rb at line 76 solved my
problem

img = img.crop(::Magick::CenterGravity, [img.columns, w].min,
                         [img.rows, h].min,true)
This topic is locked and can not be replied to.