Write to pdf does not respect depth or alpha off IM 6.9.7.5 Q16 Mac OSX

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Write to pdf does not respect depth or alpha off IM 6.9.7.5 Q16 Mac OSX

Post by fmw42 »

.
When I take an opaque image with no alpha channel and convert to pdf format, the result contains an opaque alpha channel and insists on being 16 bit, even though I add -depth 8 -alpha off. Using GS 9.16

Is this a limitation of Ghostscript or Imagemagick?

For example:

Logo:

Code: Select all

Image: LOGO
  Base filename: 
  Format: GIF (CompuServe graphics interchange format)
  Mime type: image/gif
  Class: PseudoClass
  Geometry: 640x480+0+0
  Units: Undefined
  Type: Palette
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
  Channel statistics:
    Pixels: 307200
    Red:
      min: 4 (0.0156863)
      max: 255 (1)
      mean: 229.323 (0.899307)
      standard deviation: 69.3423 (0.271931)
      kurtosis: 4.45973
      skewness: -2.49768
      entropy: 0.186315
    Green:
      min: 0 (0)
      max: 255 (1)
      mean: 226.217 (0.887127)
      standard deviation: 70.8689 (0.277917)
      kurtosis: 3.37246
      skewness: -2.24758
      entropy: 0.203574
    Blue:
      min: 0 (0)
      max: 255 (1)
      mean: 229.064 (0.898288)
      standard deviation: 64.1018 (0.251379)
      kurtosis: 4.65272
      skewness: -2.42185
      entropy: 0.206184
convert logo: -alpha off -depth 8 logo.pdf

Code: Select all

Image: logo.pdf
  Format: PDF (Portable Document Format)
  Mime type: application/pdf
  Class: DirectClass
  Geometry: 640x480+0+0
  Resolution: 72x72
  Print size: 8.88889x6.66667
  Units: Undefined
  Type: PaletteAlpha
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 16/8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
    alpha: 1-bit
  Channel statistics:
    Pixels: 307200
    Red:
      min: 1028 (0.0156863)
      max: 65535 (1)
      mean: 58936.1 (0.899307)
      standard deviation: 17821 (0.271931)
      kurtosis: 4.45973
      skewness: -2.49768
      entropy: 0.186315
    Green:
      min: 0 (0)
      max: 65535 (1)
      mean: 58137.8 (0.887127)
      standard deviation: 18213.3 (0.277917)
      kurtosis: 3.37246
      skewness: -2.24758
      entropy: 0.203574
    Blue:
      min: 0 (0)
      max: 65535 (1)
      mean: 58869.3 (0.898288)
      standard deviation: 16474.2 (0.251379)
      kurtosis: 4.65272
      skewness: -2.42185
      entropy: 0.206184
    Alpha:
      min: 65535 (1)
      max: 65535 (1)
      mean: 65535 (1)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
      entropy: 0
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Write to pdf does not respect depth or alpha off IM 6.9.7.5 Q16 Mac OSX

Post by magick »

Edit delegates.xml and change the ps:alpha device from pngalpha to pnmraw. That eliminates the alpha channel, not sure about the image depth. You could also use this command line: convert logo.pdf -alpha off -depth 8 logo.pdf logo.png.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Write to pdf does not respect depth or alpha off IM 6.9.7.5 Q16 Mac OSX

Post by fmw42 »

You could also use this command line:

convert logo.pdf -alpha off -depth 8 logo.pdf logo.png.
Did you really mean two output images (pdf and png)?

I am not sure I understand this command. Why would I reprocess my output image (logo.pdf)?

I can get rid of the alpha channel using pnmraw. Thanks.

But I still get 16 bit results rather than 8 bits, even if I do

Code: Select all

convert logo.pdf -depth 8 logo.pdf
or

Code: Select all

convert logo: -alpha off -depth 8 PNG:- | convert - logo.pdf
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Write to pdf does not respect depth or alpha off IM 6.9.7.5 Q16 Mac OSX

Post by magick »

The depth of the image is defined by the Ghostscript device you utilize to read the PDF. You can use whatever device you want, type 'gs -h' and it lists all the devices your instance of Ghostscript supports.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Write to pdf does not respect depth or alpha off IM 6.9.7.5 Q16 Mac OSX

Post by fmw42 »

Thanks. I will look into that. Are all the devices listed by gs available for use with IM?

Is the same sDEVIDE used for reading and writing PDF? If so, I have a problem, since my client wants to read a PDF with transparency and then flatten it on white and write it out without transparency. That was the issue with using pngalpha that you pointed out. So if I change the sDEVICE from pnmraw to pngalpha, will I still be able to read a transparent PDF. I have verified that with pnmraw, it writes one without an opaque alpha channel correctly.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Write to pdf does not respect depth or alpha off IM 6.9.7.5 Q16 Mac OSX

Post by magick »

If you need transparency, you need the pngalpha device.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Write to pdf does not respect depth or alpha off IM 6.9.7.5 Q16 Mac OSX

Post by fmw42 »

Thanks
Post Reply