Created
March 28, 2025 18:10
-
-
Save BirkhoffLee/405cb8353d512d587e6e3335c4de1f5a to your computer and use it in GitHub Desktop.
Apply scanner effect to a PDF with imagemagick (using nix-shell)
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 zsh | |
# Apply scanner effect to a PDF | |
# Credits: | |
# https://gist.github.com/andyrbell/25c8632e15d17c83a54602f6acde2724 | |
# https://github.com/NixOS/nixpkgs/issues/138638#issuecomment-1068569761 | |
dirtypdf () { | |
if [ $# -ne 2 ]; then | |
echo "Usage: dirtypdf <input_pdf> <output_pdf>" | |
return 1 | |
fi | |
input_file="$1" | |
output_file="$2" | |
if [ ! -f "$input_file" ]; then | |
echo "Error: Input file '$input_file' does not exist" | |
return 1 | |
fi | |
nix-shell --packages 'imagemagickBig' --run "magick -density 90 \"$input_file\" -rotate 0.5 -attenuate 0.2 +noise Multiplicative -colorspace Gray \"$output_file\"" | |
# open the output file in macOS Finder | |
open -R "$output_file" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment