Last active
February 11, 2016 11:08
-
-
Save tsega/c0a338c357bcfc94d09c to your computer and use it in GitHub Desktop.
A ruby command line script to generate jpg's from the first pages of pdf files.
This file contains 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 characters
#!/usr/bin/env ruby | |
# This require that you have ImageMagick and Ghostscript installed and available on your PATH | |
# It also assumes you have you pdf files in `pdfs` folder | |
# Note: Since it generates jpg's it does not handle transparency very well | |
# modify the .jpg to .png to generate png files. | |
Dir['pdfs/*.pdf'].each do |pdf_file| | |
jpg_file = pdf_file.chomp(File.extname(pdf_file)) + ".jpg" | |
system("convert -density 144 #{pdf_file}[0] -resize 200x300 #{jpg_file} ") | |
end |
These thumbnails will be around for decades, on god-only-knows-what-resolution devices right?
Usually, keeping a high-resolution copy that you could manipulate on the fly is a good idea. Progress in the Responsive Images community is promising in getting rid of the whole device-screen nightmare.
We could always re-process them, you're right. For now, they need to be high-quality enough to be used wherever our partners might use them, for example:
The size of these is more or less ok, but the quality is horrible.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I prefer GraphicsMagick, the ImageMagick fork with better code quality, more sane command line options, and a less annoying developer. :)
The results are very similar obviously! One tip, I prefer the "x600" notation, which gives 600px height at whatever width is appropriate for the aspect ratio—hey, these thumbnails will be around for decades, on god-only-knows-what-resolution devices right?
edit: Also, there are diminishing returns in JPEG quality after around 85 or so, so I always use 82–85.