Any image to PNG

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
doublemax
Posts: 6
Joined: 2015-12-02T14:38:27-07:00
Authentication code: 1151

Any image to PNG

Post by doublemax »

Hello,

Is there a single command line to convert any image to a PNG?
`display` works for all images we have tried - but `convert` did not.

We have problems with multiple layer images. Testcase:
wget "http://doppelbauer.name/psd-layers.psd"
convert -coalesce "psd-layers.psd" -background none -flatten single-layer.png
convert -coalesce "psd-layers.psd" -background none multiple-layer.mng
display "psd-layers.psd" : works
display "single-layer.png" : failed - white image
display "multiple-layer.mng" : works
Thanks a lot!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Any image to PNG

Post by fmw42 »

What IM version and platform are you on? Please always provide that.

What do you get from

Code: Select all

convert -version
does it include the png delegate library?

What is not working about the png result? Are you trying to get a transparent background? If the png file has no transparency, then just using -background none -flatten or just -background none will not change that. You need to use -transparent somecolor, where somecolor is the color you want to change to transparent.

Can you post your input image to some free hosting such as dropbox.com and put the URL here so we can test with it?

Also note that -coalesce is not likely to affect psd files as they are not optimized as in gif and if used, it should appear after the input image.
doublemax
Posts: 6
Joined: 2015-12-02T14:38:27-07:00
Authentication code: 1151

Re: Any image to PNG

Post by doublemax »

Thanks a lot,

My problem: The "flatten" image is simply white.
Goal: A commandline "Uploaded image goes in - image for everyone (=png/jpeg) comes out".

Testcase:
http://doppelbauer.name/psd-layers.psd
I don't use dropbox - but you may use a proxy, e.g.: https://hide.me/de/proxy
Commandline:
convert "psd-layers.psd" -flatten "test.png"
display test.png
Version:
Version: ImageMagick 6.9.2-7 Q16 x86_64 2015-12-02 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC OpenMP
Delegates (built-in): bzlib fontconfig freetype jbig jng jpeg lzma openexr pangocairo png tiff x xml zlib
Thanks!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Any image to PNG

Post by fmw42 »

In most cases, a flattened layer of the PSD file is the first layer. So for PSD files you should be able to use

Code: Select all

convert psd-layers.psd[0] psd-layers.png
That works for me on IM 6.9.2.7 Q16 Mac OSX. Adding [0] to any non-layered file will not hurt, since the first layer [0] is the only layer.

However, note that Imagemagick does not generally know about all the "fancy" layers in a PSD file. (Yours has many of these, but they do not seem to be doing anything to the base image.) It only can handle simple layers. So you may not be able to extract other individual layers.

If the above does not work, then check your version of libpng.
Post Reply