png -sample changes png format

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
zak
Posts: 7
Joined: 2016-11-23T16:41:47-07:00
Authentication code: 1151

png -sample changes png format

Post by zak »

I'm upscaling rgba pngs with sample, I save a 8bit/channel RGB png with transparent parts in photoshop(its rgba) and I run:

Code: Select all

for /f "tokens=*" %%a in (dimensions10.txt) do magick convert %filename% -sample %%ax%%a  out\%filename%-%%a.png  
I have also tried this and all combinations of these 2:

Code: Select all

magick convert %filename%  -channel rgba -alpha on -interpolate Nearest -filter point -define png32:bit-depth=8 -resize %%ax%%a out\%filename%-%%a.png
Now when I load the resulting pngs back to photoshop it says indexed color.
Interestingly this produces the exact format I want I guess:

Code: Select all

magick convert -size %%ax%%a -interpolate Nearest -filter point -background none -fill purple -gravity center -font Arial-Bold label:"%%a" %%a.png
So how can I keep the exact format on the convert -sample on the top?

Other thing, I tried to pack a png into an icon with auto resize which works also with the above filters and everything, loses transparency though.
Also I can't pack bigger than 256px images inside,
and the 256px in the ico is always corrupted when I open it in an editor, I can find no info about controlling the output ico on the documentation.

Please help me.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: png -sample changes png format

Post by fmw42 »

If you want to save a PNG as 24bit color, then preface the output with PNG24:output.png. If you want 8bit color (palette), the preface the output with PNG8:output.png. If you want 32 bit color (24 bit rgb and 8 bit alpha), then preface the output with PNG32:output.png

see http://www.imagemagick.org/Usage/formats/#png_formats
zak
Posts: 7
Joined: 2016-11-23T16:41:47-07:00
Authentication code: 1151

Re: png -sample changes png format

Post by zak »

I have tried all these before with no luck, png24: even tried png:32 and all of them with "-channel rgba -alpha on", still I get pngs with indexed colors.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: png -sample changes png format

Post by fmw42 »

Then try from http://www.imagemagick.org/Usage/formats/#png_write

-define png:bit-depth=24

just before the output
zak
Posts: 7
Joined: 2016-11-23T16:41:47-07:00
Authentication code: 1151

Re: png -sample changes png format

Post by zak »

I already tried it, and now again and the result is the same.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: png -sample changes png format

Post by fmw42 »

I will defer to the PNG developer on this as I have exhausted my thoughts.
zak
Posts: 7
Joined: 2016-11-23T16:41:47-07:00
Authentication code: 1151

Re: png -sample changes png format

Post by zak »

Thank You!
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: png -sample changes png format

Post by glennrp »

The PNG developer would like to know what version of IM you are using and on what platform (Windows, I suppose, because of the %%'s).
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: png -sample changes png format

Post by glennrp »

fmw42 wrote:Then try from http://www.imagemagick.org/Usage/formats/#png_write

-define png:bit-depth=24

just before the output
png:bit-depth must be 1, 2, 4, 8, or 16. An attempt to set it to 24 will be silently ignored.
zak
Posts: 7
Joined: 2016-11-23T16:41:47-07:00
Authentication code: 1151

Re: png -sample changes png format

Post by zak »

I'm on 7.0.3-7 Q16 x64 2016-11-15 on win10
I have tried all possible combinations of the above mentioned parameters(in the whole topic), no luck.

Also, if I do this:

Code: Select all

magick convert -size %%ax%%a -interpolate Nearest -filter point -background #55ffff -fill #ff55ff -gravity center -font Arial-Bold label:"%%a" %%a.png
Then I get a 16 bit / channel image why?

If I use:

Code: Select all

magick convert -size %%ax%%a -interpolate Nearest -filter point -background none -fill blue -gravity center -font Arial-Bold label:"%%a" %%a.png
I get a 8bit / channel image as intended with rgba.

If I run:

Code: Select all

magick convert -size %%ax%%a -interpolate Nearest -filter point -background none -fill blue -gravity center -font Arial-Bold label:"%%a" -define png:bit-depth=8 %%a.png
I'll get indexed color.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: png -sample changes png format

Post by glennrp »

If you want rgba8888 then ask for "png32:%%a.png" as output. You don't need to define the png:bit-depth because png32 implies bit-depth=8.
zak
Posts: 7
Joined: 2016-11-23T16:41:47-07:00
Authentication code: 1151

Re: png -sample changes png format

Post by zak »

For this:

Code: Select all

magick convert %filename% -channel rgba -alpha on -sample %%ax%%a  -define png32:out\%filename%-%%a.png 
I get this:

Code: Select all

convert:  `png32:out\p.png-20.png' @ error/convert.c/ConvertImageCommand/3250.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: png -sample changes png format

Post by fmw42 »

Remove the -define

Code: Select all

magick convert %filename% -channel rgba -alpha on -sample %%ax%%a  png32:out\%filename%-%%a.png
or

Code: Select all

magick %filename% -channel rgba -alpha on -sample %%ax%%a  png32:out\%filename%-%%a.png
zak
Posts: 7
Joined: 2016-11-23T16:41:47-07:00
Authentication code: 1151

Re: png -sample changes png format

Post by zak »

Thank You it works!

I can loose the "-channel rgba -alpha on" also (png32=rgba8888) , right? I mean whatever my input format is, if there is transparency then it will be retained without those swiches?
Post Reply