lib/papercrop/helpers.rb
# Form helper to render the main cropping box of an attachment.
# Loads the original image. Initially the cropbox has no limits on dimensions, showing the image at full size.
# You can restrict it by setting the :width option to the width you want.
#
#   cropbox :avatar, :width => 650
#
# You can override the aspect ratio used by Jcrop, and even unlock it by setting :aspect to a new value or false
# 
#   cropbox :avatar, :width => 650, :aspect => false
#
# @param attachment [Symbol] attachment name
# @param opts [Hash]
Form helper to render the main cropping box of an attachment.
Loads the original image. Initially the cropbox has no limits on dimensions, showing the image at full size.
You can restrict it by setting the :width option to the width you want.

cropbox :avatar, :width => 650

You can override the aspect ratio used by Jcrop, and even unlock it by setting :aspect to a new value or false

cropbox :avatar, :width => 650, :aspect => false
Form helper to render the main cropping box of an attachment . Loads the original image . Initially the cropbox has no limits on dimensions showing the image at full size . You can restrict it by setting the : width option to the width you want . cropbox : avatar : width = > 650 You can override the aspect ratio used by Jcrop and even unlock it by setting : aspect to a new value or false cropbox : avatar : width = > 650 : aspect = > false
def cropbox(attachment, opts = {})
      attachment      = attachment.to_sym
      original_width  = self.object.image_geometry(attachment, :original).width.to_i
      original_height = self.object.image_geometry(attachment, :original).height.to_i
      box_width       = opts.fetch :width,  original_width
      aspect          = opts.fetch :aspect, self.object.send(:"#{attachment}_aspect")
      if self.object.send(attachment).class == Paperclip::Attachment
        box  = self.hidden_field(:"#{attachment}_original_w", :value => original_width)
        box << self.hidden_field(:"#{attachment}_original_h", :value => original_height)
        box << self.hidden_field(:"#{attachment}_box_w",      :value => box_width)
        box << self.hidden_field(:"#{attachment}_aspect",     :value => aspect, :id => "#{attachment}_aspect")
        for attribute in [:crop_x, :crop_y, :crop_w, :crop_h] do
          box << self.hidden_field(:"#{attachment}_#{attribute}", :id => "#{attachment}_#{attribute}")
        end
        crop_image = @template.image_tag(self.object.send(attachment).url)
        box << @template.content_tag(:div, crop_image, :id => "#{attachment}_cropbox")
      end
    end
def cropbox ( attachment , opts = { } ) attachment = attachment . to_sym original_width = self . object . image_geometry ( attachment , :original ) . width . to_i original_height = self . object . image_geometry ( attachment , :original ) . height . to_i box_width = opts . fetch :width , original_width aspect = opts . fetch :aspect , self . object . send ( :" #{ attachment } _aspect " ) if self . object . send ( attachment ) . class == Paperclip :: Attachment box = self . hidden_field ( :" #{ attachment } _original_w " , :value => original_width ) box << self . hidden_field ( :" #{ attachment } _original_h " , :value => original_height ) box << self . hidden_field ( :" #{ attachment } _box_w " , :value => box_width ) box << self . hidden_field ( :" #{ attachment } _aspect " , :value => aspect , :id => "#{attachment}_aspect" ) for attribute in [ :crop_x , :crop_y , :crop_w , :crop_h ] do box << self . hidden_field ( :" #{ attachment } _ #{ attribute } " , :id => "#{attachment}_#{attribute}" ) end crop_image = @template . image_tag ( self . object . send ( attachment ) . url ) box << @template . content_tag ( :div , crop_image , :id => "#{attachment}_cropbox" ) end end
Form helper to render the main cropping box of an attachment.
Form helper to render the main cropping box of an attachment .
attachment
None
opts
<not_specific>
<not_specific>
None