Skip to content

Instantly share code, notes, and snippets.

@the-architect
Created December 10, 2009 09:52
Show Gist options
  • Save the-architect/253246 to your computer and use it in GitHub Desktop.
Save the-architect/253246 to your computer and use it in GitHub Desktop.
PDF2PNG PDF Thumbnail Generator
require 'rubygems'
require 'RMagick'
class Pdf2PngConverter
def initialize(*files)
files.each do |file|
pdf = Magick::ImageList.new(file)
filename = "#{File.join(File.dirname(file), File.basename(file, '.*'))}.png"
pdf[0].resize_to_fit(100,100).write(filename)
# gem install smusher:
# `smusher --service PunyPng #{filename}`
end
end
end
if ARGV.any?
if ARGV.size > 1
Pdf2PngConverter.new(*Dir.glob(ARGV))
else
Pdf2PngConverter.new(*Dir.glob(ARGV[0]))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment