[Resolved] PNG file created with IM not opening in mspaint

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
SnowUse
Posts: 7
Joined: 2011-02-03T07:59:44-07:00
Authentication code: 8675308

[Resolved] PNG file created with IM not opening in mspaint

Post by SnowUse »

I'm posting this in Users as I'm highly confident that this isn't a bug/lack of format support, but just something I haven't yet understood.

Aims & Objectives
I am trying to use IM on Solaris to create a fairly simple PNG file with the following requirements: 600x80; transparent background; a text message in grey left-justified wrapping Verdana size 10.

A bit of reading and I found that caption would handle my text wrapping for me, and the colour bit was easy.

After starting to use IM yesterday afternoon, I came up with the following command line:

Code: Select all

convert -size 600x80 xc:transparent -fill "rgb(81, 98, 111)"  -font /path/to/Verdana.ttf -pointsize 10 -gravity West caption:' Here is my message. It does not contain any unescaped single quotes. The quick brown fox jumps over the lazy example. The quick brown fox jumps over the lazy example. The quick brown fox jumps over the lazy example.' /path/to/output.png
(edited because I put canvas: in the example when I meant to write xc: as I am using an older version)

This worked fantastically well - I transferred the resulting file to a Windows box and opened it in Internet Explorer (yes, yes, I know... but I'm working in a corporate environment so this is a requirement). The image displayed fine.

Issue
Then I tried to open the PNG file in mspaint. Or include it in a PDF. In either case, no joy.

mspaint reports that "Paint cannot read this file. This is not a valid bitmap file. or its format is not currently supported."

Any ideas? Can anyone give me a 'clean' convert command line which will produce a basic PNG file with some text in from scratch?

Further info
IM version: Version: ImageMagick 6.6.0-10 2010-04-03 Q16 http://www.imagemagick.org
System running IM: SunOS <hostname goes here> 5.10 Generic_141445-09 i86pc i386 i86pc

I realise I'm not on the latest version. However, unless you have specific information about a relevant bug which is fixed in a later version, please don't just tell me I need to upgrade. I would love to, but it's not a trivial operation as the servers are administered by another department in another country.

I have done some googling and list/examples/forum reading around this but have failed thus far to understand what I am doing wrong; any pointers gratefully received.
Last edited by SnowUse on 2011-02-09T13:54:31-07:00, edited 4 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PNG file created with IM not opening in mspaint

Post by fmw42 »

try xc:transparent or xc:none rather than canvas:transparent Both should work, but canvas is newer.

Also there has been quite a bit of work on PNG over the last number of releases. In some releases PNG was not producing correct results. This might be your case. Try upgrading. See the changelog for all the PNG changes: http://www.imagemagick.org/script/changelog.php

I am not on a PC, so some other windows user may be able to verify your problem.
SnowUse
Posts: 7
Joined: 2011-02-03T07:59:44-07:00
Authentication code: 8675308

Re: PNG file created with IM not opening in mspaint

Post by SnowUse »

Thanks fmw42.

Oops, I meant to write xc: in my example (instead of canvas:). You are quite right that the version I am on does not support canvas: and I have been using xc: to generate the image.

I am creating the image on a Solaris box, not Windows. I don't have an X interface to the Solaris box so can't view the image there. To view it, I transfer it to a Windows PC (which is where the image will eventually be displayed by a client-side application which receives the image from a server app on the Solaris box).

As I mentioned, upgrading is not straightforward for me (and will result in a delay to my project) so I'd love to find a simple working example instead and work outwards from there.

Reading through the changelog, a majority of PNG-related fixes involve transparency and pallette. I tried a red background with no joy. Is there a way of switching off transparency altogether for a PNG image?
Last edited by SnowUse on 2011-02-07T07:32:15-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PNG file created with IM not opening in mspaint

Post by fmw42 »

Reading through the changelog, a majority of PNG-related fixes involve transparency and pallette. I tried a red background with no joy. Is there a way of switching off transparency altogether for a PNG image?

try adding +matte to your command.

When your image is generated, run

identify -verbose info: yourimage

and see what is the Type.

You can force png to 24 bits without transparency by suffixing the output with PNG24:yourimage

So try that also
SnowUse
Posts: 7
Joined: 2011-02-03T07:59:44-07:00
Authentication code: 8675308

Re: PNG file created with IM not opening in mspaint

Post by SnowUse »

Thanks for these further practical suggestions. I now have:

Code: Select all

convert -size 600x80  -fill "rgb(81, 98, 111)"  -font /path/to/Verdana.ttf -pointsize 10 -gravity West caption:'Test message. Test message. Test message. Test message. Test message. Test message. Test message. Test message. Test message. Test message.' +matte PNG24:/path/to/output.png
Even with matte and PNG24:, identify gives:

Code: Select all

identify: no decode delegate for this image format `/path/to/output.png' @ error/constitute.c/ReadImage/533.
It's not looking good for me, is it? :( I'll start seeing about that upgrade.

Are you (or someone) able to provide a simple-as-possible example of using convert to create any PNG image?
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: PNG file created with IM not opening in mspaint

Post by glennrp »

What is the output of

Code: Select all

convert -list format | grep NG
? That will give us an idea of what
libpng version you are using.

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

Re: PNG file created with IM not opening in mspaint

Post by fmw42 »

identify: no decode delegate for this image format `/path/to/output.png' @ error/constitute.c/ReadImage/533.
This may mean that you have not installed the PNG delegate library before installing IM (or it is corrupt). Type

convert -list configure

and see what you have in the line starting with DELEGATES. For example, I have

DELEGATES bzlib fftw fontconfig freetype gs jpeg jng jp2 lcms lqr mpeg openexr png rsvg tiff x11 xml zlib

If you installed IM manually, then you need to first install any image delegate (png, jpg, tiff, etc) that you want to be able to use, then re-install IM. If you installed from binary, then it should have been installed with IM.

type

convert logo: logo.png

Do you still get that error message from that command?



This seems to work fine for me:


convert -size 100x -fill "rgb(81, 98, 111)" -font /library/fonts/verdana.ttf -pointsize 10 -gravity West \
caption:'Test message. Test message. Test message. Test message. Test message.' \
+matte PNG24:tmp.png

Though the verbose info: shows a type of Palette. But there is no transparency.
SnowUse
Posts: 7
Joined: 2011-02-03T07:59:44-07:00
Authentication code: 8675308

Re: PNG file created with IM not opening in mspaint

Post by SnowUse »

Code: Select all

convert -list format | grep NG
      3FR  DNG       r--   Hasselblad CFV/H3D39II
      ARW  DNG       r--   Sony Alpha Raw Image Format
      CR2  DNG       r--   Canon Digital Camera Raw Image Format
      CRW  DNG       r--   Canon Digital Camera Raw Image Format
      DCR  DNG       r--   Kodak Digital Camera Raw Image File
      DNG  DNG       r--   Digital Negative
      ERF  DNG       r--   Epson RAW Format
      JNG* PNG       rw-   JPEG Network Graphics
           See http://www.libpng.org/pub/mng/ for details about the JNG
      K25  DNG       r--   Kodak Digital Camera Raw Image Format
      KDC  DNG       r--   Kodak Digital Camera Raw Image Format
      MNG* PNG       rw+   Multiple-image Network Graphics (libpng 1.2.41,1.2.44)
           See http://www.libpng.org/pub/mng/ for details about the MNG
      MRW  DNG       r--   Sony (Minolta) Raw Image File
      NEF  DNG       r--   Nikon Digital SLR Camera Raw Image File
      ORF  DNG       r--   Olympus Digital Camera Raw Image File
      PEF  DNG       r--   Pentax Electronic File
      PNG* PNG       rw-   Portable Network Graphics (libpng 1.2.41,1.2.44)
           See http://www.libpng.org/ for details about the PNG format.
    PNG24* PNG       rw-   opaque 24-bit RGB (zlib 1.2.4,1.1.4)
    PNG32* PNG       rw-   opaque or transparent 32-bit RGBA
     PNG8* PNG       rw-   8-bit indexed with optional binary transparency
      RAF  DNG       r--   Fuji CCD-RAW Graphic File
      SR2  DNG       r--   Sony Raw Format 2
      SRF  DNG       r--   Sony Raw Format
      X3F  DNG       r--   Sigma Camera RAW Picture File

Code: Select all

convert -list configure | grep DELEGATES
DELEGATES     bzlib fontconfig freetype gvc jpeg jng lcms mpeg png rsvg tiff x11 xml zlib
I can confirm that the simple logo: example still results in an apparently corrupt file, so something isn't quite right with my local installation. I'm not sure how IM was installed on this machine as I am not the administrator. I have tracked down the name of the person who [probably] installed it and will speak to them on Monday (they've already left the office for the day).

Thank you both for your thoughts.
SnowUse
Posts: 7
Joined: 2011-02-03T07:59:44-07:00
Authentication code: 8675308

Re: PNG file created with IM not opening in mspaint

Post by SnowUse »

Resolved: an upgrade to 6.6.7-5 did fix this issue. Not sure what the specific change is, but my PNGs now open in mspaint.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: [Resolved] PNG file created with IM not opening in mspai

Post by glennrp »

Code: Select all

PNG24* PNG       rw-   opaque 24-bit RGB (zlib 1.2.4,1.1.4)
You compiled with zlib-1.2.4 but are running with 1.1.4.
I'm not sure zlib is backward compatible enough to do
that without problems.

You may have to tinker with your configuration FLAGS or
LD_LIBRARY_PATH (or maybe just find zlib-1.1.4 and
get rid of it!)
Post Reply