2

スケールではなく、ペーパークリップをトリミングしたい(この抜粋の:full1を参照)

class Graphic < ActiveRecord::Base
  has_attached_file :image, :styles => { :full0 => "940x1000#" #want it to scale, and crop if neccessary
                                         :full1 => "940#", #want it to crop width, not scale
                                       }

:full1を機能させたいのですが、機能しません。「作業」とは、画像の幅をトリミングする必要があることを意味しますが、高さには何もしません。その理由は、Webスクリーンショットをアップロードしていて、幅940px(中央から)にトリミングしたいのですが、高さはそのままにしておく必要があります。私がペーパークリップについて研究している限り、これを行う方法を見つけていません。

どうやらそれはImageMagickによって完全にサポートされているようです:http://www.imagemagick.org/Usage/crop/#crop_stripしかし、これをレール上のペーパークリップに詰め込む方法がわかりません。

どうもありがとう!

4

2 に答える 2

0

画像処理のオプションをユーザー変換できます。次は、画像を中央でトリミングします。

has_attached_file :profile_picture, :storage => :s3,                             
                                     :styles => { :medium => "", :thumb => ""},
                                      :convert_options => {
                                          :thumb => Proc.new { |instance| instance.thumnail_dimension },
                                          :medium => Proc.new { |instance| instance.thumnail_dimension(300) }
                                          }

def thumnail_dimension(size=100)
    dimensions = Paperclip::Geometry.from_file(profile_picture.queued_for_write[:original].path)
    min = dimensions.width > dimensions.height ? dimensions.height : dimensions.width
    "-gravity Center -crop #{min}x#{min}+0+0 +repage -resize #{size}x#{size}^"
  end
于 2013-03-20T07:26:38.987 に答える
0

問題にならないように、高さをとてつもなく大きいものに設定していただけませんか?

class Graphic < ActiveRecord::Base
  has_attached_file :image, :styles => { :full0 => "940x1000#" #want it to scale, and crop if neccessary
                                         :full1 => "940x9999999#", #want it to crop width, not scale
                                       }

940pxより広いものはトリミングされると思います。

于 2013-03-20T06:18:57.333 に答える