Croping of thumbnails from top to middle

17 views
Skip to first unread message

Niels

unread,
Apr 15, 2009, 12:29:02 PM4/15/09
to Paperclip Plugin
Hi folks,

I'm searching for a possibility to tell ImageMagick through Paperclip
that it should generate the cropping not with a centered focus, but
with a focus on top.

My szenario is an upload of a PDF file, where I get generated the
thumbnails from the first page. But I want a cropped version with
60x60 pixel, starting on the top of the first page of the pdf. At the
moment my declaration is working with this config:

has_attached_file :media,
:styles => { :thumbnail => ["60x60#", :png], :normal =>
["600x600>", :png] },
:default_style => :normal,
:storage => :filesystem,
:default_url => "/files/:class/missing_:style.png",
:url => "/files/:class/:hashing/:id/:style/:basename.:extension",
:path => ":rails_root/public/
files/:class/:hashing/:id/:style/:basename.:extension"

I think I have to pass "-gravity Center" to ImageMagick, but it
doesn't work out, when I try this in the convert_options. Does anybody
have an advice for me - would be very nice.

Thanks for your help.

Niels.

Ricardo S Yasuda

unread,
Apr 15, 2009, 12:57:41 PM4/15/09
to papercli...@googlegroups.com
What I did was overwrite the cropping method on class Geometry to:

    def cropping dst, ratio, scale
      if ratio.horizontal? || ratio.square?
        "%dx%d+%d+%d" % [ dst.width, dst.height, 0, 0 ]
      else
        "%dx%d+%d+%d" % [ dst.width, dst.height, (self.width * scale - dst.width) / 2, 0 ]
      end
    end

Niels

unread,
Apr 15, 2009, 2:16:33 PM4/15/09
to Paperclip Plugin
Hi Ricardo,

> What I did was overwrite the cropping method on class Geometry
Well, this would be one way, but I have also other models in my
application using the "normal" cropping in the current way. So the
global overwrite of the method isn't a solution.

Could a special crop processor help me in this situation?

Niels.
Reply all
Reply to author
Forward
0 new messages