Skip to content

Instantly share code, notes, and snippets.

@tsega
Last active February 11, 2016 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsega/c0a338c357bcfc94d09c to your computer and use it in GitHub Desktop.
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.
#!/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
@alanorth
Copy link

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:

https://ccafs.cgiar.org/publications/how-countries-plan-address-agricultural-adaptation-and-mitigation

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