Skip to content

Instantly share code, notes, and snippets.

@yosriady
Created August 27, 2014 15:01
Show Gist options
  • Select an option

  • Save yosriady/dc0a3be9637f2f3380cc to your computer and use it in GitHub Desktop.

Select an option

Save yosriady/dc0a3be9637f2f3380cc to your computer and use it in GitHub Desktop.
Preview of PDF Paperclip Processor
module Paperclip
# Handles generating preview images of Sheet PDFs
class Preview < Processor
def initialize(file, options = {}, attachment = nil)
super
@file = file
@instance = options[:instance]
@current_format = File.extname(@file.path)
@basename = File.basename(@file.path, @current_format)
end
def make
dst = Tempfile.new([@basename, 'png'].compact.join("."))
dst.binmode
image= MiniMagick::Image.open(File.expand_path(@file.path))
image.format('png')
image.write(File.expand_path(dst.path))
dst.flush
return dst
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment