2009-07-22 11 views
4

imagemagickにすべてのサムネイルにドロップシャドウを適用させることで、クリップのサムネイルの処理を変更したいと思います。私が執着しているのは、この小さな奇跡を取り除く実際のイメージマジックコマンドです。私が試したすべてが、元の画像がない、間違ってスケールされたドロップシャドウを返します。imagemagickとpaperclipを使用してサムネイルにドロップシャドウを適用するにはどうすればよいですか?

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

(私は本当に名前を嫌い、私が今までプロジェクトを復活させる場合は、おそらくそれを変更します)。.. RubyShopそれを呼ばれるとドキュメントに私の頭を埋め私はついにそれを理解した。

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スタイルにのみ変換を適用します。すべてを使用すると、すべてのスタイルに変換が適用されます。
  4. "70x4 + 0 + 0"を調整して、必要なシャドウを取得します。
1

imagemagick自体にコマンドラインオプションを送信するのではなく、rmagickインターフェイスを使うほうがずっと簡単です。

rmagickを使用する場合は、シャドウ方法を使用できます。

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

画像をシャドウで合成します。

私はrmagickを使って記事を書いた:http://schf.uc.org/articles/2006/10/18/render-greatlooking-collages-with-ruby-and-rmagick

はそれの上にそれを読んで試してみてくださいあなたのより良い理解を与えるかもしれません。

私はまた、より使いやすくしようとするrmagickへの抽象ライブラリを書いています。 私はそれがPhotoshopのレイヤーベースの合成を模倣しようとしたので、いくつかの試行錯誤の後