4

imagemagick ですべてのサムネイルにドロップ シャドウを適用して、ペーパークリップのサムネイルの処理を変更したいと思います。私が立ち往生しているのは、この小さな奇跡を実現する実際の imagemagick コマンドです。私が試したことはすべて、元の画像なしで誤ってスケーリングされたドロップ シャドウを返します。

def transformation_command
  scale, crop = @current_geometry.transformation_to(@target_geometry, crop?)
  trans = ""
  trans << " -resize \"#{scale}\""
  trans << " -crop \"#{crop}\" +repage" if crop
  # Apply Drop Shadow
  trans << " #{convert_options}" if convert_options? 
  trans
end

私が試したもの...

def transformation_command
  scale, crop = @current_geometry.transformation_to(@target_geometry, crop?)
  trans = ""
  trans << " -resize \"#{scale}\""
  trans << " -crop \"#{crop}\" +repage" if crop
  trans << " \( +clone -background black -shadow 60x5+10+10 \) +swap -background none -layers merge +repage"
  trans << " #{convert_options}" if convert_options? 
  trans
end

私はimagemagickにまったく慣れていません。どんな助けでも大歓迎です。

4

2 に答える 2

4

いくつかの試行錯誤とドキュメントに頭を埋めた後、私はついにそれを理解しました.

has_attached_file :image, 
  :styles => { :thumb => ["100x100#", :png] }, 
  :convert_options => { :thumb => '\( +clone -background black -shadow 70x4+0+0 \) +swap -background none -layers merge +repage' }
  1. ImageMagick の最新バージョンがインストールされていることを確認してください。
  2. ["100x100#", :png] は画像を png に変換し、ドロップ シャドウが透明になるようにします。
  3. 変換オプションの下で、:thumb は変換を :thumb スタイルにのみ適用し、:all を使用してすべてのスタイルに変換を適用します。
  4. 「70x4+0+0」を微調整して、必要な影を取得します。
于 2009-07-24T18:34:38.113 に答える
1

コマンド ライン オプションを imagemagick 自体に送信するよりも、rmagick インターフェイスを使用する方がずっと簡単だと思います。

rmagick を使用する場合は、シャドウ メソッドを使用できます。

img = Image.read('slide.png').first
shadow = img.shadow(0, 0, 0.0, '20%')

次に、影の上に画像を合成します。

rmagick の使用に関する記事を書きました

読み返してみると、より理解が深まるかもしれません。

また、rmagick をさらに使いやすくするための抽象化ライブラリも作成しました。Photoshop レイヤーベースの合成を模倣しようとしたため、 RubyShopと呼びました.. (私はこの名前が本当に嫌いで、プロジェクトを復活させたらおそらく変更するでしょう)

于 2009-07-23T15:59:21.513 に答える