Created
July 6, 2012 09:58
-
-
Save bastien/3059321 to your computer and use it in GitHub Desktop.
Revisions
-
bastien revised this gist
Jul 6, 2012 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,4 @@ module Paperclip class Ghostscript < Processor attr_accessor :current_geometry, :target_geometry, :format, :whiny, :convert_options, :source_file_options -
bastien created this gist
Jul 6, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ # Model using the ghostscript processor class Content < ActiveRecord::Base has_attached_file :resource, :styles => { :preview => ["725x1200>", :jpg], :thumb => ["100x140>", :jpg] }, :processors => [:ghostscript, :thumbnail], :convert_options => { :all => '-colorspace RGB -flatten -density 300 -quality 100' }, :path => ":page_path/:class/:id/:resource_token/:style/:filename" end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ module Paperclip # Created to answer a single need, converting pdf to rgb before resizing them, because it at once with ImageMagick 6.6.6 wasn't working # Since heroku isn't using 6.6.6 yet the call to this proessor is commented out in the content.rb class class Ghostscript < Processor attr_accessor :current_geometry, :target_geometry, :format, :whiny, :convert_options, :source_file_options def initialize file, options = {}, attachment = nil super @file = file @format = options[:format] @current_format = File.extname(@file.path) @basename = File.basename(@file.path, @current_format) end def make src = @file dst = Tempfile.new([@basename, @format ? ".#{@format}" : '']) dst.binmode begin parameters = [] parameters << "-dNOPAUSE -dBATCH -sDEVICE=jpeg -r144 -dUseCIEColor -dFirstPage=1 -dLastPage=1" parameters << "-sOutputFile=:dest" parameters << ":source" parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ") success = Paperclip.run("gs", parameters, :source => "#{File.expand_path(src.path)}", :dest => File.expand_path(dst.path)) rescue PaperclipCommandLineError => e raise PaperclipError, "There was an error processing the thumbnail for #{@basename}" if @whiny end dst end end end