PNG comments commands

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
cejones
Posts: 8
Joined: 2019-05-20T12:05:48-07:00
Authentication code: 1152

PNG comments commands

Post by cejones » 2019-05-21T07:57:33-07:00

In past versions of IM, I was able to do this command:

Code: Select all

identify -format %c image.png > comments.txt 
and it would save out the contents of the comments for image.png into comments.txt

It seems that this command no longer works in the current version of IM (ImageMagick 6.9.10-11 Q16 x86_64 2018-09-08)
Am I doing something wrong or has the syntax slightly changed for the above command?

Searching through forums here and elsewhere, I found this newer command:

Code: Select all

convert image.png -format "%c" info: > comments.txt
which does work and outputs the comments which I think fixes my needs to read out the comments.

I need to save out the comments of a PNG file, make a minor edit to the comments, and then save the new comments into a new version of the PNG file.

Again, in the past versions of IM, I used this command to copy back the comments:

Code: Select all

convert -comment @comments.txt original.png new.png
This unfortunately gives me errors... that look similar to this:

Code: Select all

convert: unable to open image `Dynamics: No such file or directory @ error/blob.c/OpenBlob/2873.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/560.
convert: unable to open image `Areamap': No such file or directory @ error/blob.c/OpenBlob/2873.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/560.
convert: unable to open image `file': No such file or directory @ error/blob.c/OpenBlob/2873.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/560.
convert: unable to open image `version': No such file or directory @ error/blob.c/OpenBlob/2873.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/560.
... it goes on for a long list showing each word in the text file...
The first line of my comments.txt file is this:

"Molecular Dynamics Areamap file version 1.7, run with Areafill"

and it looks like it is parsing each individual word and spewing out these errors. This used to work with no errors in previous versions of IM.

I have also tried this:

Code: Select all

convert -set comment @comments.txt image.png
which also outputs the same errors as above.

I thought perhaps that my comments.txt file was somehow screwy, so I did a dos2unix to make sure the EOL were correct, but that did not resolve it either.

Any help is greatly appreciated.

Chris
Austin, TX

User avatar
fmw42
Posts: 25106
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PNG comments commands

Post by fmw42 » 2019-05-21T09:30:49-07:00

You have to read the image first with -set comment, then you need an output image.

Try this:

# create png file from IM logo: image

Code: Select all

convert logo: logo.png
# add comment to logo.png

Code: Select all

convert logo.png -set comment "This is a test" logo.png
# check the comment

Code: Select all

convert logo.png -format "%c\n" info:
This is a test
# write comment to text.txt file

Code: Select all

convert logo.png -format "%c" info: > text.txt
# clear the comment

Code: Select all

convert logo.png -set comment "" logo.png
# check that it is cleared

Code: Select all

convert logo.png -format "%c\n" info:

# read the comment back into the png file from the text file

Code: Select all

convert logo.png -set comment "@text.txt" logo.png
# check the comment

Code: Select all

convert logo.png -format "%c\n" info:
This is a test

cejones
Posts: 8
Joined: 2019-05-20T12:05:48-07:00
Authentication code: 1152

Re: PNG comments commands

Post by cejones » 2019-05-21T09:59:18-07:00

Thank you fmw42... It is a nice step by step on how to read and set comments. Everything works as expected until the second to last command where i get this:

Code: Select all

$ convert logo.png -set comment "@text.txt" logo.png
convert: unable to open image `is': No such file or directory @ error/blob.c/OpenBlob/2873.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/560.
convert: unable to open image `a': No such file or directory @ error/blob.c/OpenBlob/2873.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/560.
convert: unable to open image `test': No such file or directory @ error/blob.c/OpenBlob/2873.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/560.
I also tried it without the quotations around @text.txt but it gives the same errors.

With these errors, it does set the comment to testing but leaves out the rest. The space after testing seems to stop it from considering the rest of the txt file as part of the comment. Very odd.

cejones
Posts: 8
Joined: 2019-05-20T12:05:48-07:00
Authentication code: 1152

Re: PNG comments commands

Post by cejones » 2019-05-21T10:12:24-07:00

Well, I figured out how to resolve this issue:

Code: Select all

convert logo.png -set comment {@text.txt} logo.png
I guess the text file name needed to be inside curly brackets. All works for me now.

Thanks again!

User avatar
fmw42
Posts: 25106
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PNG comments commands

Post by fmw42 » 2019-05-21T10:28:11-07:00

I have never seen that. I know of no reason to put it in curly brackets. What is your IM version and platform? Have you edited your policy.xml file to permit the use of @ for file reading? See https://imagemagick.org/script/resources.php

cejones
Posts: 8
Joined: 2019-05-20T12:05:48-07:00
Authentication code: 1152

Re: PNG comments commands

Post by cejones » 2019-05-21T11:08:55-07:00

Code: Select all

identify -version

Version: ImageMagick 6.9.10-11 Q16 x86_64 2018-09-08 https://www.imagemagick.org
Copyright: © 1999-2018 ImageMagick Studio LLC
License: https://www.imagemagick.org/script/license.php
Features: Cipher DPC OpenMP
Delegates (built-in): autotrace bzlib cairo fftw fontconfig fpx freetype gslib jbig jng jp2 jpeg lcms lzma pangocairo png ps rsvg tiff webp x xml zlib
Running IM in Cygwin on a Windows 10 box. (Which I suspect is the issue here)

I have not edited the policy.xml file

snibgo
Posts: 11787
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: PNG comments commands

Post by snibgo » 2019-05-21T11:20:50-07:00

It works fine for me, IM 6.9.9-50 on Windows 8.1 with Cygwin:

Code: Select all

$ convert toes.png -set comment @comment.txt t.png

$ convert toes.png t.png -format %c info:
This is a test.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 25106
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PNG comments commands

Post by fmw42 » 2019-05-21T12:28:16-07:00

cejones wrote:Running IM in Cygwin on a Windows 10 box.
Why Cygwin? Windows 10 has built-in Unix

formkory
Posts: 2
Joined: 2019-06-07T11:55:55-07:00
Authentication code: 1152

Re: PNG comments commands

Post by formkory » 2019-06-07T12:03:41-07:00

I'm having issues with comments on my machine for some reason... once I've set them once, they get really screwy. I ran through your steps here to see what the result was, and everything was perfectly fine until the very last step. I didn't get any errors, but it didn't output anything. Similarly with my own steps, any time I write a new image and write a comment, I can retrieve it just fine. But if I try to change it (to anything) it gets screwy and blanks it out. I feel like I'm missing a step or something, but I can't figure out what it is. I'm running the following version:

Version: ImageMagick 6.9.6-2 Q16 x86_64 2019-02-01 http://www.imagemagick.org

Here's a sequence that I just ran. It set, retrieved, set again, retrieved, and then when I tried a third time, it was just blank.

Code: Select all

convert logo: logo.png
convert logo.png -set comment "This is a test" logo.png
convert logo.png -format "%c\n" info:
This is a test
convert logo.png -set comment "new comment" logo.png
convert logo.png -format "%c\n" info:
new comment
convert logo.png -set comment "another comment" logo.png
convert logo.png -format "%c\n" info:

fmw42 wrote:
2019-05-21T09:30:49-07:00
You have to read the image first with -set comment, then you need an output image.

Try this:

# create png file from IM logo: image

Code: Select all

convert logo: logo.png
# add comment to logo.png

Code: Select all

convert logo.png -set comment "This is a test" logo.png
# check the comment

Code: Select all

convert logo.png -format "%c\n" info:
This is a test
# write comment to text.txt file

Code: Select all

convert logo.png -format "%c" info: > text.txt
# clear the comment

Code: Select all

convert logo.png -set comment "" logo.png
# check that it is cleared

Code: Select all

convert logo.png -format "%c\n" info:

# read the comment back into the png file from the text file

Code: Select all

convert logo.png -set comment "@text.txt" logo.png
# check the comment

Code: Select all

convert logo.png -format "%c\n" info:
This is a test

User avatar
fmw42
Posts: 25106
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PNG comments commands

Post by fmw42 » 2019-06-07T12:29:18-07:00

6.9.6-2 is ancient. Perhaps it had a bug. You might try upgrading 6.9.10.48 is current.

formkory
Posts: 2
Joined: 2019-06-07T11:55:55-07:00
Authentication code: 1152

Re: PNG comments commands

Post by formkory » 2019-06-07T12:33:41-07:00

Ancient? It says 2/1/2019! haha. I'll try that tho... thanks

User avatar
fmw42
Posts: 25106
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PNG comments commands

Post by fmw42 » 2019-06-07T12:34:37-07:00

If on Linux, then they often patch without changing the version number. So you could be OK.

Perhaps try removing Cygwin and use the built in Unix on Windows 10.

Post Reply