A Bash one-liner for printing GIF comics emailed from gocomics
My son likes comics (Calvin & Hobbes, Sarah's scribbles, etc...) so I like to include one in his lunchbox each day. With my gocomics.com subscription I get emailed a set of comics each morning and I save the images to be printed later by my receipt printer. For the last year my bash one-liner has worked without fail, until today - the first day of a new schoolyear. I had a problem on my hands and had to figure it out fast.
These errors were getting in the way:
mogrify-im6.q16: no decode delegate for this image format `' @ error/constitute.c/ReadImage/581.
lp: Unsupported document-format "image/gif".
References
- ITPP047/ITPP098P Driver Download and Installation [support.munbyn.com]
- How to install Linux Driver for MUNBYN ITPP047 [u.pcloud.link]
- http://localhost:631/ [OpenPrinting CUPS Local Interface]
- Rotate images from terminal [askubuntu.com]
- ImageMagick command to convert and save with same name [stackoverflow.com]
- How to rotate a set of pictures from the command line? [unix.stackexchange.com]
- Batch converting PNG to JPG in linux [superuser.com]
- How can I specify "fit to page" when printing on the command line with lpr? [askubuntu.com]
- Print using lpr command - How to print without scaling? [askubuntu.com]
- How to find all JPG files on the file system when .jpg extension is not obligatory ? [unix.stackexchange.com]
Background
Gocomics.com will send out daily emails with comic images linked in the message. These images are GIFs. My process is to right click and save interesting comics for my son into an 'ingest' folder and then use my receipt printer to bulk-print out a set of comics via a bash one-liner that I had put together which looked like this:
mogrify -rotate 90 * || true && sleep 1 && find . -maxdepth 1 -not -type d | xargs lp -d Printer_POS-ITPP047 && find . -maxdepth 1 -not -type d -exec mv -n {} ./old/ \;
It's a bit gnarly and gets the job done.
Recently I upgraded (did a fresh install) to Ubuntu 24.04 and setup my printer driver per the manufacturer instructions. Initial testing showed I could print text and I left it at that. However, once I tried to run the above script it generated these errors:
- mogrify-im6.q16: no decode delegate for this image format `' @ error/constitute.c/ReadImage/581.
- lp: Unsupported document-format "image/gif".
Solution
There appears to be some change in CUPS between the version shipped with Ubuntu 22.04 and 24.04. I don't appear to be able to get the lp command to print a GIF (even a single-frame gif like the ones sent from gocomics.com) in 24.04. This required me to alter my one-liner to include a format conversion which so far seems to be working. Here are the changes broken out:
- mogrify -rotate 90 -format jpg * ## This includes a flag to change the format to JPEG
- find . -maxdepth 1 -name '*.jpg' -not -type d ## The find command now looks for images with a .jpg extension, ignoring the gif files
- lp -d Printer_POS-80C -o scaling=100 ## Set the printer name along with a scaling flag, otherwise images print too small
- find . -maxdepth 1 -not -name '*.jpg' -not -type d ## This ensures that the original gif file is copied out to the 'old' directory for records
- && rm -f *.jpg ## Finally, remove the jpeg intermediary files (I don't want to save them)
And here's the completed, working bash one liner:
mogrify -rotate 90 -format jpg * || true && sleep 1 && find . -maxdepth 1 -name '*.jpg' -not -type d | xargs lp -d Printer_POS-80C -o scaling=100 && find . -maxdepth 1 -not -name '*.jpg' -not -type d -exec mv -n {} ./old/ \; && rm -f *.jpg