Last active
January 23, 2016 14:25
-
-
Save nottrobin/fc3e82afbb28f673ecc8 to your computer and use it in GitHub Desktop.
An imagemagick script to convert a PDF to a greyscaled & inverted version (for a unix-based system)
This file contains hidden or 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 bash | |
| ## | |
| # Usage: | |
| # ./grey-invert.sh my-doc.pdf | |
| # | |
| # This will: | |
| # - Convert to images and store in a /tmp directory | |
| # - Greyscale images | |
| # - Invert images | |
| # - Rename images to their proper order | |
| # - Convert images back to a PDF named "{filename}-grey-invert.pdf" | |
| # | |
| # The only dependency is imagemagick | |
| ## | |
| file=$1 | |
| dir=$(mktemp -d) | |
| convert -density 150 ${file} -quality 90 ${dir}/${file}.png | |
| mogrify -colorspace Gray ${dir}/*.png | |
| mogrify -negate ${dir}/*.png | |
| rename 's/-(\d+)/sprintf("-%05d", $1)/e' ${dir}/*.png | |
| convert ${dir}/*.png ${file}-grey-invert.pdf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment