Skip to content

Instantly share code, notes, and snippets.

@ErichDonGubler
Last active March 10, 2026 16:59
Show Gist options
  • Select an option

  • Save ErichDonGubler/0377570cef83bde5c655339380765b08 to your computer and use it in GitHub Desktop.

Select an option

Save ErichDonGubler/0377570cef83bde5c655339380765b08 to your computer and use it in GitHub Desktop.
# Take all provided images and put them into PDF using Python's Pillow library.
#
# Uses `uvx`. If you don't have it, you will need to install it.
#
# # Examples
@example "turn pages from scans into a PDF" { ls ~/Downloads/scanned_images | get name | images-to-pdf }
export def "main" [
--to: oneof<path, nothing>,
# The output path of the PDF.
]: list<path> -> nothing {
if (which uvx | is-empty) {
error make --unspanned {
msg: "`uvx` isn't on `PATH`; do you need to install it?"
}
}
if $to == null {
error make --unspanned {
msg: "`--to` can't be `null`, please specify"
}
}
let to = $to | to nuon
let paths_list_nuon = $in | to nuon
let python_script = [
'from PIL import Image'
$"images = [Image.open\(f\) for f in ($paths_list_nuon)]"
$"images[0].save\(($to), save_all=True, append_images=images[1:]\)"
] | str join '; '
uvx --with pillow python -c $python_script
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment