imagick icon indicating copy to clipboard operation
imagick copied to clipboard

Problem with PHP 8.3 and in-memory-stream.

Open temp opened this issue 1 year ago • 5 comments

I'm having problems with imagick and in-memory-streams on PHP 8.3. Here are two test cases, one with in-memory-stream, which results in an error, one with a file-stream, this one works fine. Both throw NO error on PHP 8.2.

File 1:

<?php

$stream = fopen('php://memory', 'wb+');

$image = new Imagick('magick:rose');
$image->setImageFormat('jpg');
$image->writeImageFile($stream);

rewind($stream);

$image = new Imagick();
$image->readImageFile($stream);

echo 'done'.PHP_EOL;

Run File 1:

$ php test1.php
PHP Fatal error:  Uncaught ImagickException: no decode delegate for this image format `' @ error/constitute.c/ReadImage/746 in /app/test1.php:11
Stack trace:
#0 /app/test1.php(11): Imagick->readImageFile()
#1 {main}
  thrown in /app/test1.php on line 11

File 2:

<?php

$stream = fopen('/tmp/test.jpg', 'wb+');

$image = new Imagick('magick:rose');
$image->setImageFormat('jpg');
$image->writeImageFile($stream);

rewind($stream);

$image = new Imagick();
$image->readImageFile($stream);

echo 'done'.PHP_EOL;

Run File 2:

$ php test2.php
done

JPG support is enabled:

php --ri imagick

imagick

imagick module => enabled
imagick module version => @PACKAGE_VERSION@
imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
Imagick compiled with ImageMagick version => ImageMagick 7.1.1-22 Q16-HDRI aarch64 21779 https://imagemagick.org
Imagick using ImageMagick library version => ImageMagick 7.1.1-22 Q16-HDRI aarch64 21779 https://imagemagick.org
ImageMagick copyright => (C) 1999 ImageMagick Studio LLC
ImageMagick release date => 2023-12-03
ImageMagick number of supported formats:  => 219
ImageMagick supported formats => 3G2, 3GP, AAI, AI, APNG, ART, ASHLAR, AVI, AVS, BAYER, BAYERA, BGR, BGRA, BGRO, BMP, BMP2, BMP3, BRF, CAL, CALS, CANVAS, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CUBE, CUR, CUT, DATA, DCM, DCX, DDS, DFONT, DOT, DPX, DXT1, DXT5, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, FARBFELD, FAX, FF, FILE, FITS, FL32, FLV, FRACTAL, FTP, FTS, FTXT, G3, G4, GIF, GIF87, GRADIENT, GRAY, GRAYA, GROUP4, GV, HALD, HDR, HISTOGRAM, HRZ, HTM, HTML, HTTP, HTTPS, ICB, ICO, ICON, INFO, INLINE, IPL, ISOBRL, ISOBRL6, JNG, JNX, JPE, JPEG, JPG, JPS, JSON, KERNEL, LABEL, M2V, M4V, MAC, MAP, MASK, MAT, MATTE, MIFF, MKV, MNG, MONO, MOV, MP4, MPC, MPEG, MPG, MPO, MSL, MTV, MVG, NULL, ORA, OTB, OTF, PAL, PALM, PAM, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PES, PFA, PFB, PFM, PGM, PGX, PHM, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG00, PNG24, PNG32, PNG48, PNG64, PNG8, PNM, POCKETMOD, PPM, PS, PS2, PS3, PSB, PSD, PTIF, PWP, QOI, RADIAL-GRADIENT, RAS, RGB, RGB565, RGBA, RGBO, RGF, RLA, RLE, SCR, SCT, SFW, SGI, SHTML, SIX, SIXEL, SPARSE-COLOR, STEGANO, STRIMG, SUN, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TM2, TTC, TTF, TXT, UBRL, UBRL6, UIL, UYVY, VDA, VICAR, VID, VIFF, VIPS, VST, WBMP, WEBM, WEBP, WMV, WPG, X, XBM, XC, XCF, XPM, XPS, XV, XWD, YAML, YCbCr, YCbCrA, YUV

Directive => Local Value => Master Value
imagick.locale_fix => 0 => 0
imagick.skip_version_check => 0 => 0
imagick.progress_monitor => 0 => 0
imagick.set_single_thread => 1 => 1
imagick.shutdown_sleep_count => 10 => 10
imagick.allow_zero_dimension_images => 0 => 0

temp avatar Jan 03 '24 12:01 temp

Additional info: On my mac the error does not occur with php 8.3, the ImageMagick Version is 6.9.x, the error occurs in a docker container with the official docker php image, and manually compiled imagick extension (which uses ImageMagick 7.1.x, as seen above).

temp avatar Jan 15 '24 10:01 temp

Hi,

I'm unable to reproduce this with PHP 8.3.2

Is it still an issue for you?

the error occurs in a docker container with the official docker php image

Just to note, the 'official docker php image' is made by Docker, not by anyone to do with the PHP team.

Danack avatar Feb 09 '24 15:02 Danack

Thanks for your answer, Danack. Yes, this should probably be reported to docker-php. I will wait until a version of Imagick is released that is compatible with 8.3. I will use this issue here to provide 2 phpt-tests, if this is fine for you, that will demonstrate the problem.

temp avatar Feb 29 '24 07:02 temp

Thanks for the PR. I still can't reproduce the issue here, but maybe having them as part of the test suite will make it easier to demonstrate a problem somewhere.

I'm going to close this issue, as there's no action for me to take.

Feel free to add more info or open a new issue if you can tell me how to reproduce the issue.

Danack avatar Jul 02 '24 15:07 Danack

I should have waited for the CI to finish...

001+ Fatal error: Uncaught ImagickException: Unable to write image to the filehandle in D:\a\imagick\imagick\tests\013-read-filehandle-memory-stream.php:7 002+ Stack trace: 003+ #0 D:\a\imagick\imagick\tests\013-read-filehandle-memory-stream.php(7): Imagick->writeImageFile(Resource id #5)

Danack avatar Jul 03 '24 16:07 Danack