Problem with -negate on specific png file

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
fenryhord
Posts: 4
Joined: 2018-06-07T08:31:30-07:00
Authentication code: 1152

Problem with -negate on specific png file

Post by fenryhord »

Hey I am a new user and just tried the -negate function on this file (https://imgur.com/a/LNuo2F7).
If i use this line: "magick convert base.png -negate negate_base.png" is doesnt work. It just gives me a black image.

with this: "magick convert base.png -negate negate_base.jpg" it works.
It also works when i rename the png file to "*.jpg"???? (no clue why) and alter the code to fit the new file-ending.

Maybe somebody can help here?

regards
fenryhord
Posts: 4
Joined: 2018-06-07T08:31:30-07:00
Authentication code: 1152

Re: Problem with -negate on specific png file

Post by fenryhord »

Ok did some testing with the -channel attribute.
When i specify -channel RGB it works with this: "magick convert base.png -channel RGB -negate negate_base.png"
Isn't RGB the default one?
regards
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem with -negate on specific png file

Post by fmw42 »

Your image has transparency. JPG does not support transparency. Using -channel rgb tells IM to only negate channels r, g, b (each separately) and not alpha.

So you should flatten the image first and then negate if you want to convert to JPG. Also note that with IM 7, you should use only magick and not magick convert.

Code: Select all

magick img.png -flatten -negate img7.jpg
fenryhord
Posts: 4
Joined: 2018-06-07T08:31:30-07:00
Authentication code: 1152

Re: Problem with -negate on specific png file

Post by fenryhord »

OK thanks. My initial idea was not to convert it (png -> png) which didn't worked.
I was confused when it worked when i converted (png -> jpg).

One different question for that type of image should i use jpeg or png?
regards
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem with -negate on specific png file

Post by fmw42 »

Use of JPG or PNG depends upon what you want to achieve. If you need to keep alpha, then you should use PNG. If you want the smaller file size, then use JPG. But do not use JPG for any intermediate format, only your final image.
fenryhord
Posts: 4
Joined: 2018-06-07T08:31:30-07:00
Authentication code: 1152

Re: Problem with -negate on specific png file

Post by fenryhord »

Ok thanks.
That was all.
Do i need to close this post or something?
regards.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem with -negate on specific png file

Post by fmw42 »

No you do not. But if you want to, you can go the the title of your first post in this topic and add [RESOLVED] or something like that at the beginning.
Post Reply