convert grayscale tif to psd, create very large psd-file

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.
Post Reply
mop
Posts: 7
Joined: 2016-01-06T06:35:47-07:00
Authentication code: 1151

convert grayscale tif to psd, create very large psd-file

Post by mop » 2017-10-16T01:38:49-07:00

Hi

When I convert a grayscale tif (806 K) it result in a very large psd (57 M) - 72 times bigger than the original tif.
Is this expected?

The input tif-file in this test can be found at
https://www.dropbox.com/s/343gugdo9rn9y ... e.tif?dl=0

The result is at:
https://www.dropbox.com/s/lrjg6rehh65p4 ... e.psd?dl=0

I use the command:
convert 072017McCain_grayscale.tif grayscale.psd

This is done with ImageMagick version 7.0.7-7 on Linux (redhat 7).

regards
Morten

User avatar
fmw42
Posts: 22091
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: convert grayscale tif to psd, create very large psd-file

Post by fmw42 » 2017-10-16T09:47:27-07:00

Add -compress lzw. Your input has lzw compression.

Code: Select all

convert 072017McCain_grayscale.tif -compress lzw 072017McCain_grayscale_new.tif

identify  072017McCain_grayscale.tif 072017McCain_grayscale_new.tif
072017McCain_grayscale.tif TIFF 6375x4712 6375x4712+0+0 8-bit Grayscale Gray 825332B 0.010u 0:00.009
072017McCain_grayscale_new.tif TIFF 6375x4712 6375x4712+0+0 8-bit Grayscale Gray 801852B 0.000u 0:00.000

mop
Posts: 7
Joined: 2016-01-06T06:35:47-07:00
Authentication code: 1151

Re: convert grayscale tif to psd, create very large psd-file

Post by mop » 2017-10-16T22:43:06-07:00

Thanks for your reply
But I need to convert the tif-file to a PSD-file.
And convert create a valid PSD-file, but the size is increased by a factor 72.
If I open the tif in Photoshop and save it as a PSD, the size increase by a factor 2 (1.7M).
I can not see, what the remaining 56M data contain.

regards
Morten

User avatar
fmw42
Posts: 22091
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: convert grayscale tif to psd, create very large psd-file

Post by fmw42 » 2017-10-16T23:12:04-07:00

There are several issue with converting your lzw compressed grayscale 1-bit TIFF to PSD.

PSD will be uncompressed. I tried using lzw compression, but that did not work.
PSD will include an alpha channel. I tried removing he alpha channel but that did not work.
PSD has two layers -- the same image, but one is the flattened layer and the other is the original image. Flattening does nothing. So you really have two equal layers.

All these factors increase the size of TIFF to PSD .

Code: Select all

convert -quiet 072017McCain_grayscale.tif -alpha off -compress lzw -type bilevel -depth 1 test.psd
identify test.psd
test.psd[0] PSD 6375x4712 6375x4712+0+0 1-bit Grayscale Gray 256c 7.17843MiB 0.010u 0:00.009
test.psd[1] PSD 6375x4712 6375x4712+0+0 1-bit Gray 256c 7.17843MiB 0.000u 0:00.000

Code: Select all

Image: test.psd
 Image: test.psd
  Format: PSD (Adobe Photoshop bitmap)
  Class: DirectClass
  Geometry: 6375x4712+0+0
  Resolution: 750x750
  Print size: 8.5x6.28267
  Units: PixelsPerInch
  Type: PaletteAlpha
  Endianess: MSB
  Colorspace: sRGB
  Depth: 1-bit
  Channel depth:
    red: 1-bit
    green: 1-bit
    blue: 1-bit
    alpha: 1-bit
  Channel statistics:
    Pixels: 30039000
    Red:
      min: 0  (0)
      max: 1 (1)
      mean: 0.751825 (0.751825)
      standard deviation: 0.431954 (0.431954)
      kurtosis: -0.640485
      skewness: -1.16598
      entropy: 0.808372
    Green:
      min: 1  (1)
      max: 1 (1)
      mean: 1 (1)
      standard deviation: nan (nan)
      kurtosis: 1.79958e+69
      skewness: 4.57541e+49
      entropy: nan
    Blue:
      min: 1  (1)
      max: 1 (1)
      mean: 1 (1)
      standard deviation: nan (nan)
      kurtosis: 1.79958e+69
      skewness: 4.57541e+49
      entropy: nan
    Alpha:
      min: 1  (1)
      max: 1 (1)
      mean: 1 (1)
      standard deviation: 0 (0)
      kurtosis: -3
      skewness: 0
      entropy: nan
  Image statistics:
    Overall:
      min: 1  (1)
      max: 0 (0)
      mean: 0.312044 (0.312044)
      standard deviation: 0.463328 (0.463328)
      kurtosis: -1.34174
      skewness: -0.811332
      entropy: nan
  Colors: 2
  Histogram:
   7454921: (  0,255,255,255) #00FFFFFF cyan
  22584079: (255,255,255,255) #FFFFFFFF white
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Background color: srgba(255,255,255,0)
  Border color: srgba(223,223,223,1)
  Matte color: grey74
  Transparent color: none
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 6375x4712+0+0
  Dispose: Undefined
  Iterations: 0
  Scene: 0 of 2
  Compression: None
  Orientation: Undefined
  Properties:
    date:create: 2017-10-16T23:26:40-07:00
    date:modify: 2017-10-16T23:26:40-07:00
    icc:copyright: Copyright 1999 Adobe Systems Incorporated
    icc:description: Dot Gain 20%
    icc:manufacturer: Dot Gain 20%
    icc:model: Dot Gain 20%
    signature: fcfeea68d8bb147fd69eac37a7aaedef8dfb5fc75405bcb4c005060f3c532c5e
    tiff:XResolution: 750
    tiff:YResolution: 750
  Profiles:
    Profile-8bim: 16096 bytes
    Profile-icc: 912 bytes
  Artifacts:
    filename: test.psd
    verbose: true
  Tainted: False
  Filesize: 0B
  Number pixels: 30039000
  Pixels per second: 19762500B
  User time: 5.200u
  Elapsed time: 0:02.519
  Version: ImageMagick 6.9.9-20 Q16 x86_64 2017-10-16 http://www.imagemagick.org
Image: test.psd
  Format: PSD (Adobe Photoshop bitmap)
  Class: DirectClass
  Geometry: 6375x4712+0+0
  Resolution: 750x750
  Print size: 8.5x6.28267
  Units: PixelsPerInch
  Type: PaletteAlpha
  Endianess: MSB
  Colorspace: Gray
  Depth: 1-bit
  Channel depth:
    gray: 1-bit
    alpha: 1-bit
  Channel statistics:
    Pixels: 30039000
    Gray:
      min: 0  (0)
      max: 1 (1)
      mean: 0.751825 (0.751825)
      standard deviation: 0.431954 (0.431954)
      kurtosis: -0.640485
      skewness: -1.16598
      entropy: 0.808372
    Alpha:
      min: 1  (1)
      max: 1 (1)
      mean: 1 (1)
      standard deviation: 0 (0)
      kurtosis: -3
      skewness: 0
      entropy: nan
  Colors: 2
  Histogram:
   7454921: (  0,255,255,255) #00FFFFFF graya(0,1)
  22584079: (255,255,255,255) #FFFFFFFF graya(255,1)
  Rendering intent: Undefined
  Gamma: 0.454545
  Background color: graya(255,1)
  Border color: graya(223,1)
  Matte color: graya(189,1)
  Transparent color: graya(0,0)
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 6375x4712+0+0
  Dispose: Undefined
  Iterations: 0
  Scene: 1 of 2
  Compression: None
  Orientation: Undefined
  Properties:
    date:create: 2017-10-16T23:25:06-07:00
    date:modify: 2017-10-16T23:25:06-07:00
    icc:copyright: Copyright 1999 Adobe Systems Incorporated
    icc:description: Dot Gain 20%
    icc:manufacturer: Dot Gain 20%
    icc:model: Dot Gain 20%
    label: L1
    signature: fcfeea68d8bb147fd69eac37a7aaedef8dfb5fc75405bcb4c005060f3c532c5e
    tiff:XResolution: 750
    tiff:YResolution: 750
  Profiles:
    Profile-8bim: 16096 bytes
    Profile-icc: 912 bytes
  Artifacts:
    filename: test.psd
    psd:layer.opacity: 65535
    psd:layer.x: 0
    psd:layer.y: 0
    verbose: true
  Tainted: False
  Filesize: 7.17843MiB
  Number pixels: 30039000
  Pixels per second: 2.34863MB
  User time: 18.500u
  Elapsed time: 0:13.789
  Version: ImageMagick 6.9.9-20 Q16 x86_64 2017-10-16 http://www.imagemagick.org
I am sorry, I do not know what more to try. Or if this is just the way PSD files are formed.

snibgo
Posts: 9386
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert grayscale tif to psd, create very large psd-file

Post by snibgo » 2017-10-17T08:39:13-07:00

The input image as 30 million pixels. At one byte per pixel, two images per PSD, with no compression, this takes 60 MB.

For IM v6.9.5-3, an experiment shows that the only helpful compression method is RLE. The code in psd.c shows RLE as the only compression method implemented.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 22091
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: convert grayscale tif to psd, create very large psd-file

Post by fmw42 » 2017-10-17T09:09:38-07:00

Using RLE compression as snibgo suggested, I now get

Code: Select all

convert -quiet 072017McCain_grayscale.tif -alpha off -compress rle -type bilevel -depth 1 test.psd
identify test.psd
test.psd[0] PSD 6375x4712 6375x4712+0+0 1-bit Grayscale Gray 256c 2.476MiB 0.010u 0:00.009
test.psd[1] PSD 6375x4712 6375x4712+0+0 1-bit Gray 256c 2.476MiB 0.000u 0:00.000
But the image seems corrupt and I cannot open it.

snibgo
Posts: 9386
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert grayscale tif to psd, create very large psd-file

Post by snibgo » 2017-10-17T09:44:15-07:00

Can't open it with what?

For me, using just

Code: Select all

convert 072017McCain_grayscale.tif -compress RLE x.psd
... x.psd opens fine with Photoshop CS2 v9.0 and Gimp v2.8.10 and IM v6.9.5-3. The compression is only 50%.

Using...

Code: Select all

convert 072017McCain_grayscale.tif -alpha off -compress rle -type bilevel -depth 1 x.psd
... Gimp and IM can read it, but PS can't. The compression is better, at 8%.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 22091
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: convert grayscale tif to psd, create very large psd-file

Post by fmw42 » 2017-10-17T14:51:21-07:00

snibgo wrote:Can't open it with what?
It was Mac PREVIEW, which opens the input fine. However, GraphicConverter opens the output fine. On my Mac, there is no preview icon as on the input. So that may be part of the issue for PREVIEW?

mop
Posts: 7
Joined: 2016-01-06T06:35:47-07:00
Authentication code: 1151

Re: convert grayscale tif to psd, create very large psd-file

Post by mop » 2017-10-17T23:14:54-07:00

Thanks for th ereply to snigbo and Fred.
This works very fine for me.

mop
Posts: 7
Joined: 2016-01-06T06:35:47-07:00
Authentication code: 1151

Re: convert grayscale tif to psd, create very large psd-file

Post by mop » 2017-11-01T02:38:40-07:00

Sorry. It shows up, that this was not all that fine.
When I call
convert 072017McCain_grayscale.tif -compress RLE grayscale.psd
using ImageMagick 7.0.7-7 on linux, I can not open the psd-file in Photoshop (both CS6 and CC2017).
I got the error: "Could not complete your request because an unexpected end-of-file was encountered". Smae thing happnes without the -compress clause.
But using ImageMagick 7.0.4-7 it works fine.
(ImageMagick can read the resulting file in both situations).

User avatar
fmw42
Posts: 22091
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: convert grayscale tif to psd, create very large psd-file

Post by fmw42 » 2017-11-01T10:18:11-07:00

Using IM 7.0.7.4 or 7.0.7.8 with the following command will not open with the same message in GIMP.

Code: Select all

magick 072017McCain_grayscale.tif -compress RLE grayscale.psd
Similarly for IM 6.9.9.20 (Q16 Mac OSX)

Code: Select all

convert 072017McCain_grayscale.tif -compress RLE grayscale.psd
It does not open even with -compress none.


However, if you add -strip, then it opens fine in GIMP. So something is odd in the meta data.

Code: Select all

magick 072017McCain_grayscale.tif -strip -compress RLE grayscale.psd

Post Reply