abmagick icon indicating copy to clipboard operation
abmagick copied to clipboard

Inline PGM images

Open jwilk opened this issue 2 years ago • 2 comments

In 261f3417f9bdece8091b3bc678ee58f4101e056a I tried to implement the idea of using inline PGM images, as suggested in https://news.ycombinator.com/item?id=31630396. Unfortunately, this doesn't work on Ubuntu 18.04:

[email protected]$ convert 'inline:data:image/x-portable-graymap;base64,UDUKMSAxMyAyNTUKSGVsbG8gd29ybGQhCg==' gray:hello
convert-im6.q16: unable to open image `data:image/x-portable-graymap;base64,UDUKMSAxMyAyNTUKSGVsbG8gd29ybGQhCg==': No such file or directory @ error/blob.c/OpenBlob/2701.
convert-im6.q16: no images defined `gray:hello' @ error/convert.c/ConvertImageCommand/3258.

That's odd, because this feature is documented in /usr/share/doc/imagemagick-doc/html/www/formats.html:

INLINE RW Base64-encoded inline image The inline image look similar to inline:data:;base64,/9j/4AAQSk...knrn//2Q==. If the inline image exceeds 5000 characters, reference it from a file (e.g. inline:inline.txt). You can also write a base64-encoded image. Embed the mime type in the filename, for example, convert myimage inline:jpeg:myimage.txt.

Curiously, it works when I drop the inline: prefix:

[email protected]$ convert 'data:image/x-portable-graymap;base64,UDUKMSAxMyAyNTUKSGVsbG8gd29ybGQhCg==' gray:-
Hello world!

But then the inline:-less form doesn't work on Ubuntu 20.04:

[email protected]$ convert 'data:image/x-portable-graymap;base64,UDUKMSAxMyAyNTUKSGVsbG8gd29ybGQhCg==' gray:-
convert-im6.q16: unable to open image `image/x-portable-graymap;base64,UDUKMSAxMyAyNTUKSGVsbG8gd29ybGQhCg==': No such file or directory @ error/blob.c/OpenBlob/2874.
convert-im6.q16: no images defined `gray:-' @ error/convert.c/ConvertImageCommand/3258.

Ugh. ☹

jwilk avatar Jun 06 '22 16:06 jwilk

Maybe try without the mime type on Ubuntu 18.x? Imagemagick can autodetect it:

convert 'inline:data:;base64,UDUKMSAxMyAyNTUKSGVsbG8gd29ybGQhCg==' gray:hello

tyingq avatar Jun 07 '22 01:06 tyingq

Nope, it doesn't work without MIME type either:

[email protected]$ convert 'inline:data:;base64,UDUKMSAxMyAyNTUKSGVsbG8gd29ybGQhCg==' gray:hello
convert-im6.q16: unable to open image `data:;base64,UDUKMSAxMyAyNTUKSGVsbG8gd29ybGQhCg==': No such file or directory @ error/blob.c/OpenBlob/2701.
convert-im6.q16: no images defined `gray:hello' @ error/convert.c/ConvertImageCommand/3258.

jwilk avatar Jun 07 '22 09:06 jwilk