Skip to content

Instantly share code, notes, and snippets.

@Cosmo
Created April 25, 2012 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Cosmo/2489482 to your computer and use it in GitHub Desktop.
Save Cosmo/2489482 to your computer and use it in GitHub Desktop.
pdf to jpg
def convert_to_previews(new_file)
name = File.basename(current_path)
images = Magick::Image.read(current_path) do
self.background_color = "white" # does not work for me :/
end
if images.length > 0
save_path = "#{Rails.root}/public/uploads/#{model.class.to_s.underscore}/file/#{model.id}/slides"
Dir.mkdir save_path unless File.exists? save_path
images.each_with_index do |image, index|
image.border!(0, 0, "white")
image.resize_to_fit!(1024, 1024).write("#{save_path}/sheet_#{index}.jpg")
image.resize_to_fit!(70, 100000).write("#{save_path}/preview_sheet_#{index}.jpg")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment