Paperclipは、フォームパラメータが処理される前にスタイルを初期化するため、カスタムサイズ変更を指定する試みは無視されます。
モデル:
attr_accessor :new_width, :new_height
has_attached_file :attachment,
styles: lambda { |attachment| attachment.instance.set_styles }
...
def set_styles
# Default thumb:
styles = { thumb: '100x100>' }
# Resize original if new sizes have been specified
if new_width and new_height
styles[:original] = "#{new_width}x#{new_height}>"
end
styles
end
ログファイルを見ると、スタイルが定義されており、コマンドが前にconvert
トリガーされ、コントローラーから渡された値が割り当てられていることがわかります。new_width
new_height
Railsサーバーのログファイル:
{:thumb=>"100x100>"} # logger.info in the model
...
# Command :: convert ... etc
# [paperclip] Saving attachments.
...
{:thumb=>"100x100>", :original=>"300x300>"} # logger.info in the model
カスタムディメンションがインスタンスに割り当てられるまでに、ImageMagickコマンドはすでにペーパークリップによってトリガーされています。
画像を処理する前に、カスタム寸法をペーパークリップに渡してスタイルを定義するにはどうすればよいですか?