Created
March 27, 2013 17:21
-
-
Save jotto/5256221 to your computer and use it in GitHub Desktop.
https://github.com/thoughtbot/paperclip/issues/1085 this is cheap hack to get the convert_options to happen before transformation so the image size stays as defined even if there are convert options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
raise "Expecting Paperclip version 3.3.1 since we are monkey patching it in application.rb" unless Paperclip::VERSION == "3.3.1" | |
module Paperclip | |
class Thumbnail < Processor | |
def make | |
src = @file | |
dst = Tempfile.new([@basename, @format ? ".#{@format}" : '']) | |
dst.binmode | |
begin | |
parameters = [] | |
parameters << source_file_options | |
parameters << ":source" | |
if transformation_command.any?{|cmd|cmd.match(/resize/)} | |
parameters << convert_options | |
parameters << transformation_command | |
else | |
parameters << transformation_command | |
parameters << convert_options | |
end | |
parameters << ":dest" | |
parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ") | |
success = convert(parameters, :source => "#{File.expand_path(src.path)}#{'[0]' unless animated?}", :dest => File.expand_path(dst.path)) | |
rescue Cocaine::ExitStatusError => e | |
raise Paperclip::Error, "There was an error processing the thumbnail for #{@basename}" if @whiny | |
rescue Cocaine::CommandNotFoundError => e | |
raise Paperclip::Errors::CommandNotFoundError.new("Could not run the `convert` command. Please install ImageMagick.") | |
end | |
dst | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jotto Thanks for your help with this. I offer back to you the following enhancements. I'm using this with Spree, so currently stuck to Paperclip 2.8.0, so changes are reflected.
I also have need to add some flags after the -resize flag, so I have included some changes in transformation_command to further hack your monkey patch. Thanks again.