Skip to content

Instantly share code, notes, and snippets.

@n2o
Last active July 11, 2020 16:25
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 n2o/c3f9df1343d0928303612af2005a23f7 to your computer and use it in GitHub Desktop.
Save n2o/c3f9df1343d0928303612af2005a23f7 to your computer and use it in GitHub Desktop.
Babashka Script to make a PDF file look like a fax by using ImageMagick

Inspired by this Gist and @coryodaniel's solution, I put the script inside a babashka script, called pdf-like-fax.clj:

#!/usr/bin/env bb
(defn pdf-like-fax [input output]
  (let [sign (rand-nth ["+" "-"])
        rotation (rand-int 1000)
        cmd (format "convert -density 150 %s -rotate %s0.%s -attenuate 0.4 +noise Multiplicative -attenuate 0.03 +noise Multiplicative -sharpen 0x1.0 -colorspace Gray %s" input sign rotation output)
        prepared-cmd (str/split cmd #" ")]
    (apply shell/sh prepared-cmd)))

(let [[input output] *command-line-args*]
  (pdf-like-fax input output))

Usage:

bb pdf-like-fax.clj input.pdf output.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment