PaperclipでImageMagickのパフォーマンスをアップする方法

January 21 [Sat], 2012, 12:49
PaperclipでJPG画像のセムネール生成寺のパフォーマンスを落とさないようにするために、convertコマンドを実行する時に「-define jpeg:size=180x120」とうようにサイズを指定するようにコードを追加してみました。
つたないコードですが、こんな感じかなと・・。もっと良い書き方あると思いますが・・・。

module Paperclip
# Handles thumbnailing images that are uploaded.
class Thumbnail < Processor

def transformation_command
p 'File Format'
p @current_format.upcase

scale, crop = @current_geometry.transformation_to(@target_geometry, crop?)
trans = []
trans << "-coalesce" if animated?
# convert -define jpeg:size=180x120 -resize 180x120 src.jpg dst.jpg
if jpg_file?
trans << "-define jpeg:size="+ %["#{scale}"] unless scale.nil? || scale.empty?
end
trans << "-resize" << %["#{scale}"] unless scale.nil? || scale.empty?
trans << "-crop" << %["#{crop}"] << "+repage" if crop
trans
end
def jpg_file?
if @current_format !=nil && @current_format.length >0 && ".JPG"== @current_format.upcase
p "JPEG FILE."
true
else
false
end
end
end
end

  • URL:http://yaplog.jp/rails3_super/archive/22
Comment
小文字 太字 斜体 下線 取り消し線 左寄せ 中央揃え 右寄せ テキストカラー リンク 絵文字 プレビューON/OFF
画像認証  [画像変更]
画像の文字 : 
利用規約に同意
 X 
禁止事項とご注意
※本名・メールアドレス・住所・電話番号など、個人が特定できる情報の入力は行わないでください。
「ヤプログ!利用規約 第9条 禁止事項」に該当するコメントは禁止します。
「ヤプログ!利用規約」に同意の上、コメントを送信してください。
プロフィール
  • ニックネーム:Rails3Sample
  • 性別:男性
  • 職業:その他
読者になる
本業では前はブログシステムの開発をやっていましたが、今はID/ポイント管理システムをやっています。
Java、Rubyをメインでやっています。Railsだけでなく、最近はJavaScriptやNoSQL、Androidアプリも興味ありやっています。多くの人から認められるエンジニアを目指して、日々勉強です。
2012年01月
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
最新コメント
QRコード