Skip to content

Instantly share code, notes, and snippets.

@revskill10
Forked from Cosmo/gist:2489482
Created October 23, 2012 03:27
Show Gist options
  • Save revskill10/3936462 to your computer and use it in GitHub Desktop.
Save revskill10/3936462 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