Page 1 of 1

Resizing PNG loses transparency

Posted: 2017-03-09T23:46:29-07:00
by MrChilBoy
I'm not sure what I'm doing wrong here but when I resize using the following command I lose the transparency of my PNG file.

This works fine (step one)

Code: Select all

magick convert logosrc.png -trim sample.png
...but this creates a white background (step 2).

Code: Select all

magick convert logosrc.png -trim -resize 600x600 sample.png
When I look at the identify -verbose of the original file and the file produced by step one, the following identifies the format (I think).

Code: Select all

Type: PaletteAlpha
Base type: TrueColorAlpha
It changes to the following after step 2 (and co-incidentally for another image I'm having issues with)

Code: Select all

Type: TrueColorAlpha
Using ImageMagick 7.0.5-1 Q16 x64 on Windows 10

Please help :)

Re: Resizing PNG loses transparency

Posted: 2017-03-10T00:46:59-07:00
by fmw42
After -trim add +repage. Does that help? If not, upload an example image to some free hosting service such as dropbox.com and put the URL here.

Also you are running the IM 6 legacy code by putting in convert. Remove the convert and just use magick.

Re: Resizing PNG loses transparency

Posted: 2017-03-10T02:05:21-07:00
by MrChilBoy
Ok, turns out to be a weird bug in Picasa Photo Viewer ...sort of.

Code: Select all

magick logosrc.png sample.png
The results :
Original file -> Image
Resulting file -> Image

They look the same to some viewers but the identify -verbose outputs are different.

If I use the following code though, the identify -verbose ends up almost identical.

Code: Select all

magick logosrc.png -strip sample.png
Anyway, thanks for the tip about just using magick :)

Re: Resizing PNG loses transparency

Posted: 2017-03-10T02:14:59-07:00
by MrChilBoy
Not sure why the links aren't working to the images :(

Original File -> https://dl.dropboxusercontent.com/u/992 ... ogosrc.png Image
Resulting File -> https://dl.dropboxusercontent.com/u/99232980/sample.png Image

Re: Resizing PNG loses transparency

Posted: 2017-03-10T11:02:56-07:00
by fmw42
The two images are identical in pixel data.

Code: Select all

compare -metric rmse logosrc.png sample.png null:
0 (0)

Code: Select all

identify logosrc.png sample.png
logosrc.png PNG 197x201 197x201+0+0 8-bit sRGB 16.3KB 0.000u 0:00.000
sample.png PNG 197x201 197x201+0+0 8-bit sRGB 14.7KB 0.000u 0:00.000
The IM converted file may be slightly smaller size, because its zip compression may more efficient than the result from whatever tool you used

The IM converted file has three extra PNG meta tags:

Code: Select all

 png:bKGD: chunk was found (see Background color, above)
    png:cHRM: chunk was found (see Chromaticity, above)
    png:gAMA: gamma=0.45454544 (See Gamma, above)
So perhaps a different version of libpng was used. What tool created your original PNG?

Try adding an sRGB profile to each and see if they view the same. When I do:

Code: Select all

convert logosrc.png -profile /Users/fred/images/profiles/sRGB.icc logosrc_prof.png
convert sample.png -profile /Users/fred/images/profiles/sRGB.icc sample_prof.png
then they view the same.