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

プロフィール
  • ニックネーム: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コード