Imagick 1687 upgrade to 1690 errors IO error writing tag data

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
sir8472
Posts: 7
Joined: 2018-12-13T00:22:38-07:00
Authentication code: 1152

Imagick 1687 upgrade to 1690 errors IO error writing tag data

Post by sir8472 »

After a recent update to my production environment, I seem to be having problems with writing certain TIFF files. I’ve produced a cut-down PHP code snippet that reflects what’s happening in production:

Code: Select all

$img = new Imagick('source_1.png');
$img->setImageFormat('tiff');
$img->setType(\Imagick::IMGTYPE_TRUECOLORMATTE);
$img->transformImageColorspace(\Imagick::COLORSPACE_SRGB);
$img->setImageDepth(8);
file_put_contents('output_fpc', $img→getImageBlob());
This seems to fail silently, but when trying to open the TIFF it claims to be corrupt.

Modifying this code slightly, I’ve been able to produce a run-time error:

Code: Select all

$img = new Imagick('source_1.png');
$img->setImageFormat('tiff');
$img->setType(\Imagick::IMGTYPE_TRUECOLORMATTE);
$img->transformImageColorspace(\Imagick::COLORSPACE_SRGB);
$img->setImageDepth(8);
file_put_contents('output_fpc', $img→getImageBlob());
$img->writeImage('output_igk');
This is the error I’m seeing:

PHP Fatal error: Uncaught ImagickException: IO error writing tag data. `TIFFWriteDirectoryTagData' @ error/tiff.c/TIFFErrors/604

Working Conditions:

Debian Stretch base install with the following changes:

Code: Select all

apt-get update && apt-get install -y php-cli php-imagick

Code: Select all

    PHP 7.0.33-0+deb9u7 (cli) (built: Feb 16 2020 15:11:40) ( NTS )
    [versionNumber] => 1687
    [versionString] => ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org

Failure Conditions:

Debian Buster base install with the following changes:

Code: Select all

apt-get update && apt-get install -y php-cli php-imagick

Code: Select all

    PHP 7.3.14-1~deb10u1 (cli) (built: Feb 16 2020 15:07:23) ( NTS )
    [versionNumber] => 1690
    [versionString] => ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org
Files with embedded offsets seem to be more likely to fail.

I've attached some affected files here, but it is a temporary link (open to a better way to share files!):
https://send.firefox.com/download/7cc3b ... giY_voPJsQ

As I see it, there's two potential workarounds:
1. Maintain an older version of Debian/Imagick
2. Rewrite the core of the project's file storage to allow writeImage() to be passed instead of getImageBlob()

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

Re: Imagick 1687 upgrade to 1690 errors IO error writing tag data

Post by fmw42 »

Is the issue with Imagick or Imagemagick? Can you run the equivalent command in a terminal window in command line code or via PHP exec() to test?

sir8472
Posts: 7
Joined: 2018-12-13T00:22:38-07:00
Authentication code: 1152

Re: Imagick 1687 upgrade to 1690 errors IO error writing tag data

Post by sir8472 »

Apologies, I'm still finding my way around the forums. This is issue relates to imagick, the PHP implementation only. I'm able to run the following command and generate a TIFF file without issue:

Code: Select all

convert -format tiff -type TrueColorAlpha -colorspace sRGB -depth 8 storage/app/raw/2020/2/19/704608e4d1c1dad6cfba95a589a9f55f_5e4d468961ed1 output_cli

Post Reply