Skip to content

Instantly share code, notes, and snippets.

@asiansteev
Created September 13, 2016 02:42
Show Gist options
  • Save asiansteev/15d1191333de44b95011777db0c61078 to your computer and use it in GitHub Desktop.
Save asiansteev/15d1191333de44b95011777db0c61078 to your computer and use it in GitHub Desktop.
require 'mini_magick'
# for converting images from http://www.thecoverproject.net to printable pdfs.
# open 8.5x14 blank pdf
blank = MiniMagick::Image.open('blank_legal.jpg')
Dir.glob("input/*.jpg").each do |input_file|
p input_file
# open jpg
image = MiniMagick::Image.open(input_file)
# rotate jpg 90 degrees
image.rotate "90"
# place jpg in center of pdf
result = blank.composite(image) do |c|
c.compose 'Over'
c.gravity 'center'
end
# write pdf
result.format 'pdf'
result.write 'output' + input_file[5..-4] + 'pdf'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment