Imagick: Load remote files into Imagick
Greetings,
I will replicate what I originally explained here (apparently the wrong place for the issue). Without no real evidences, the thoughts points to a problem related to Alpine versions > 3.7.0 accordingly with @Danack, the maintainer of Imagick.
So my problem after hours of debug, resulted in this: PHP release <= 7.1.20 works fine with Imagick against this snippet php -r "new \Imagick('https://file-examples.com/wp-content/uploads/2017/10/file_example_JPG_100kB.jpg');"
however > 7.1.20 the snippet always fail with
Fatal error: Uncaught ImagickException: no decode delegate for this image format `' @ error/constitute.c/ReadImage/560 in Command line code:1
Stack trace:
#0 Command line code(1): Imagick->__construct('https://file-ex...')
#1 {main}
thrown in Command line code on line 1
I think it's not related to PHP version directly but with the imagemagick binaries that ships with the alpine version that holds every PHP image. Concluding that the snippet above always fails for imagemagick 7.0.8-68
or higher (this version is present in PHP 7.1.21-fpm-alpine image).
Here are some Dockerfiles what I said before:
PHP 7.1.20 imagemagick 7.0.7-11 imagick extension version 3.4.4 alpine 3.7.0 result: exits with error code 1 meaning that the PHP script worked fine
FROM php:7.1.20-fpm-alpine
RUN set -eux; \
apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS imagemagick-dev libtool \
&& export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" \
&& pecl install imagick-3.4.4 \
&& docker-php-ext-enable imagick \
&& apk add --no-cache --virtual .imagick-runtime-deps imagemagick \
&& apk del .phpize-deps
RUN set -eux; \
php -r "new \Imagick('https://file-examples.com/wp-content/uploads/2017/10/file_example_JPG_100kB.jpg');" \
&& exit 1
PHP 7.1.21
imagemagick 7.0.8-68
imagick extension version 3.4.4
alpine 3.8.1
result: Fatal error: Uncaught ImagickException: no decode delegate for this image format `' @ error/constitute.c/ReadImage/560 in Command line code:1
FROM php:7.1.21-fpm-alpine
RUN set -eux; \
apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS imagemagick-dev libtool \
&& export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" \
&& pecl install imagick-3.4.4 \
&& docker-php-ext-enable imagick \
&& apk add --no-cache --virtual .imagick-runtime-deps imagemagick \
&& apk del .phpize-deps
RUN set -eux; \
php -r "new \Imagick('https://file-examples.com/wp-content/uploads/2017/10/file_example_JPG_100kB.jpg');" \
&& exit 1
PS 1: The same problem is also reproducible against the lastest PHP version php:7.4.5-fpm-alpine
.
PS 2: Another test scenario
$imagick = new \Imagick();
$url = 'https://file-examples.com/wp-content/uploads/2017/10/file_example_JPG_100kB.jpg';
$imagick->readImageFile(fopen($url, 'rb')); // fails in the cases mentioned earlier
$imagick->readImageBlob(file_get_contents($url)); // always work
Thank you!