From cf8a3f15ee1c80b874be10cbdd34496b84560f59 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Tue, 14 Jan 2025 22:48:35 +0100 Subject: Sort guides up a bit --- guides/imagemagick.org | 81 -------------------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 guides/imagemagick.org (limited to 'guides/imagemagick.org') diff --git a/guides/imagemagick.org b/guides/imagemagick.org deleted file mode 100644 index 9d56cbf..0000000 --- a/guides/imagemagick.org +++ /dev/null @@ -1,81 +0,0 @@ -ImageMagick recipes I should stuff into config files or scripts, but -haven't yet. -* Configuration -** Allow conversion from/to PDF -- Open ImageMagick's =policy.xml= configuration file. -- Locate the == tag with a =pattern= including "PDF". -- Comment it out. -* Comparing images -~magick compare~ is a thing; ~magick convert~ can also do [[https://stackoverflow.com/a/33673440][neat stuff]]: -#+begin_src sh -convert '(' a.png -flatten -grayscale Rec709Luminance ')' \ - '(' b.png -flatten -grayscale Rec709Luminance ')' \ - '(' -clone 0-1 -compose darken -composite ')' \ - -channel RGB -combine diff.png -#+end_src - -* Adding watermarks -Someday, in the Glorious Future, every thirdparty that insists on -having a copy of my personal documents will be legally obligated to -request it from a trusted government service that steganographizes the -requester's identity in the files they send. - -Until then… -#+begin_src sh -#!/bin/bash - -set -eu - -src=$1 -dst=$2 -label=$3 - -mark () -{ - local marksrc=$1 - local markdst=$2 - - w=$(identify -format '%w\n' "$marksrc" | head -1) - h=$(identify -format '%h\n' "$marksrc" | head -1) - textw=$((w/3)) - texth=$((h/8)) - - pointsize=$((80*w/2500)) - offx=$((100*w/2500)) - offy=$((400*h/3500)) - - convert -size ${textw}x${texth} xc:none \ - -fill '#80808080' -pointsize $pointsize \ - -annotate 340x340+${offx}+${offy} "$label" \ - miff:- | \ - composite -tile - "$marksrc" "$markdst" -} - -if [[ "$src" =~ \.pdf ]] -then - # AFAICT if I feed a multi-page PDF to composite, it outputs only - # the first page. Jump through hoops to split and concatenate the - # PDF; also, roundtrip through JPG because setting -density (to - # preserve a good quality) messes with the size calculations for - # the label. - - tmpd=$(mktemp -d) - bname=$(basename "$src") - qpdf --split-pages "$src" "${tmpd}/$bname" - - shopt -s extglob - - for page in ${tmpd}/${bname/%.pdf/-+([0-9]).pdf} - do - convert -density 300 -flatten "$page" "${page/.pdf/.jpg}" - mark "${page/.pdf/.jpg}" "${page/.pdf/-MARKED.jpg}" - convert -density 300 "${page/.pdf/-MARKED.jpg}" "${page/.pdf/-MARKED.pdf}" - done - - qpdf --empty --pages ${tmpd}/${bname/%.pdf/-+([0-9])-MARKED.pdf} -- "$dst" - - exit -fi - -mark "$src" "$dst" -#+end_src -- cgit v1.2.3