Skip to content

Instantly share code, notes, and snippets.

@BirkhoffLee
Created March 28, 2025 18:10
Show Gist options
  • Save BirkhoffLee/405cb8353d512d587e6e3335c4de1f5a to your computer and use it in GitHub Desktop.
Save BirkhoffLee/405cb8353d512d587e6e3335c4de1f5a to your computer and use it in GitHub Desktop.
Apply scanner effect to a PDF with imagemagick (using nix-shell)
#!/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