-type command not working

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
gotskill10
Posts: 17
Joined: 2007-06-02T14:01:34-07:00

-type command not working

Post by gotskill10 »

I've tried this on ImageMagick 6.5.9-0 and 6.4.5.

curl -O http://s3.amazonaws.com/mixbook/4.png
convert 4.png -type TrueColor 5.png
identify -verbose 5.png | grep "Type"
>> Type: Bilevel

The image is an all black image, but I'm trying to get it to read as TrueColor, as if it had many colors. According to (http://www.imagemagick.org/script/comma ... s.php#type), this is possible to force using the "-type".

What am I missing here. This seems incredibly straightforward.

:(
gotskill10
Posts: 17
Joined: 2007-06-02T14:01:34-07:00

Re: -type command not working

Post by gotskill10 »

Can anyone try this and let me know if it works for them?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: -type command not working

Post by magick »

Use -define png:color-type=2. See http://www.imagemagick.org/script/comma ... php#define about the PNG defines.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -type command not working

Post by fmw42 »

magick wrote:Use -define png:color-type=2. See http://www.imagemagick.org/script/comma ... php#define about the PNG defines.
I have tried this for a test, but it gives an error message. Am I doing something wrong?

convert logo: -resize 50% -colorspace gray -transparent white logo2gt.png

identify -verbose logo2gt.png
Format: PNG (Portable Network Graphics)
Class: PseudoClass
Geometry: 320x240+0+0
Resolution: 72x72
Print size: 4.44444x3.33333
Units: Undefined
Type: GrayscaleMatte
Base type: GrayscaleMatte
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
gray: 8-bit
alpha: 1-bit




convert logo2gt.png -define png:color-type=6 logo2gt_t6.png

convert: Cannot write image with defined PNG:bit-depth or PNG:color-type. `logo2gt_t6.png' @ png.c/PNGErrorHandler/1455.


see http://www.imagemagick.org/Usage/formats/#png_write where it says to use 6 for RGB Matte


Even this may not work correctly?

convert logo: -resize 50% -colorspace gray -depth 8 logo2g.png
convert logo2gt.png -define png:color-type=2 logo2g_t2.png


identify logo2g_t2.png

Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 320x240+0+0
Resolution: 72x72
Print size: 4.44444x3.33333
Units: Undefined
Type: Grayscale
Base type: Grayscale
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
gray: 8-bit

Shouldn't the type be truecolor and not grayscale?

But the class has been changed to Truecolor!

I am not sure what to expect?
Last edited by fmw42 on 2010-01-27T18:28:28-07:00, edited 1 time in total.
gotskill10
Posts: 17
Joined: 2007-06-02T14:01:34-07:00

Re: -type command not working

Post by gotskill10 »

magick wrote:Use -define png:color-type=2. See http://www.imagemagick.org/script/comma ... php#define about the PNG defines.
Still doesn't work:

curl -O http://s3.amazonaws.com/mixbook/4.png
convert 4.png -define png:color-type=2 5.png
convert 5.png -type TrueColor 6.png
identify -verbose 6.png | grep "Type"
>> Type: Bilevel

Anybody else want to take a crack at this?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: -type command not working

Post by magick »

Glenn, the PNG maintainer says:
Their first try did not work because the image was grayscale. You have to prepare the image as mentioned in the "-define" documentation to be of a type that agrees with the requested output format. Use -type Truecolor to do that.

"identify" does not describe the input format, only the contents of the image. If it contains only black and white pixels, it's bilevel even if they are stored in the PNG file (or another format) as 16-bit RGB, 8-bit RGB, 8-bit GA, etc.

To find out what's really in the PNG file, use -debug coder or a 3rd-party app like pngcheck.

This works:

convert logo: -resize 50% -colorspace gray -transparent white logo2gt.png
convert logo2gt.png -type Truecolor -define png:color-type=6 logo2gt_t6.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -type command not working

Post by fmw42 »

This works:

convert logo: -resize 50% -colorspace gray -transparent white logo2gt.png
convert logo2gt.png -type Truecolor -define png:color-type=6 -debug coder logo2gt_t6.png
even doing this:

convert logo: -resize 50% -colorspace gray -transparent white logo2gt.png
convert logo2gt.png -type TruecolorMatte -define png:color-type=6 logo2gt_t6.png

The type showing in identify is still grayscalematte and not truecolormatte.

So you say that identify is not adequate to really know? Is that correct? PNGCHECK is needed then?
gotskill10
Posts: 17
Joined: 2007-06-02T14:01:34-07:00

Re: -type command not working

Post by gotskill10 »

My experience has been that I can't get this to work with JPG images either.
fmw42 wrote:
This works:

convert logo: -resize 50% -colorspace gray -transparent white logo2gt.png
convert logo2gt.png -type Truecolor -define png:color-type=6 -debug coder logo2gt_t6.png
even doing this:

convert logo: -resize 50% -colorspace gray -transparent white logo2gt.png
convert logo2gt.png -type TruecolorMatte -define png:color-type=6 logo2gt_t6.png

The type showing in identify is still grayscalematte and not truecolormatte.

So you say that identify is not adequate to really know? Is that correct? PNGCHECK is needed then?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -type command not working

Post by fmw42 »

JPG does NOT support transparency and the special -define commands are for png only.

see http://www.imagemagick.org/Usage/formats/#jpg for its own -define commands
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: -type command not working

Post by magick »

Use this command to report details about a PNG image:
  • identify -verbose -debug coder -log %e file.png
gotskill10
Posts: 17
Joined: 2007-06-02T14:01:34-07:00

Re: -type command not working

Post by gotskill10 »

This is another way to view the properties of the resulting image. Even with this, it describes the image as being Bilevel.

The core issue here is that the "-type" command is not working. According to the documentation:
Normally, when a format supports different subformats such as grayscale and truecolor, the encoder will try to choose an efficient subformat. The -type option can be used to overrride this behavior. For example, to prevent a JPEG from being written in grayscale format even though only gray pixels are present, use 'convert bird.png -type TrueColor bird.jpg'.
Back to my original example:

curl -O http://s3.amazonaws.com/mixbook/4.png
convert 4.png -type TrueColor 5.png
identify -verbose 5.png | grep "Type" (OR identify -verbose -debug coder -log %e 5.png)

This returns the "Type" as "Bilevel" no matter how you analyze the image. According to the documentation, it should be returning "TrueColor". I'm severely baffled why this is. Is this just a bug I have to deal with? I've tried this on two different computer with two different versions of IM on each.

magick wrote:Use this command to report details about a PNG image:
  • identify -verbose -debug coder -log %e file.png
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: -type command not working

Post by magick »

There is a patch in ImageMagick 6.5.9-1 Beta that should fix the problem you reported. You test it now if you download the release from ftp://ftp.imagemagick.org/pub/ImageMagick/beta.
gotskill10
Posts: 17
Joined: 2007-06-02T14:01:34-07:00

Re: -type command not working

Post by gotskill10 »

magick wrote:There is a patch in ImageMagick 6.5.9-1 Beta that should fix the problem you reported. You test it now if you download the release from ftp://ftp.imagemagick.org/pub/ImageMagick/beta.
I tested it. It still does not work. Are you sure it's fixed. Here is the output from my console: http://pastie.org/799836.

Any thoughts on how to fix this?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: -type command not working

Post by magick »

The PNG developer says "tell 'em we patched "-define" not "-type." See the ChangeLog in the source distribution.
gotskill10
Posts: 17
Joined: 2007-06-02T14:01:34-07:00

Re: -type command not working

Post by gotskill10 »

magick wrote:The PNG developer says "tell 'em we patched "-define" not "-type." See the ChangeLog in the source distribution.
This isn't working either:

$ convert --version
Version: ImageMagick 6.5.9-1 2010-01-28 Q8 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC

$ curl -O http://s3.amazonaws.com/mixbook/4.png
$ convert 4.png -define png:color-type=2 5.png
$ convert 5.png -type TrueColor 6.png
$ identify -verbose 6.png | grep "Type"
Type: Bilevel

What's next?
Post Reply