imagemagick とペーパークリップを使用してサムネイルにドロップ シャドウを適用するにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/1167983

質問

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 をまったく使用したことがありません。助けていただければ幸いです。

役に立ちましたか?

解決

いくつかの試行錯誤を繰り返し、ドキュメントに頭を埋めた後、最終的にそれを理解しました。

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」を調整して、希望の影を取得します。

他のヒント

私はそれが非常に簡単にちょうど自体をImageMagickのコマンドラインオプションを送信するというしrmagickインタフェースを使用することを見つけます。

あなたは影のメソッドを使用することができますrmagick使用している場合。

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

、次いで複合影オーバー画像

私はrmagickを使用して記事を書いた:<のhref = "http://schf.uc.org/articles/2006/10/18/render-greatlooking-collages-with-ruby-and-rmagick" のrel = "nofollowをnoreferrer"> http://schf.uc.org/articles/2006/10/18/render-greatlooking-collages-with-ruby-and-rmagick の

あなたのより良い理解を与えるかもしれない、それの上にそれを読んでみます。

私はまた、使用することをさらに容易にするために試みるrmagickする抽象化のlibを書きました。 私はそれを呼ばれる RubyShop のそれはPhotoshopのレイヤーベースの合成を模倣しようとしたので...(私は本当に名前を嫌い、私が今までプロジェクトを復活させる場合は、おそらくそれを変更します)。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top