imagick
imagick copied to clipboard
Bug(?) non-conforming drawing primitive definition `text' @ error/draw.c/RenderMVGContent/4469
PHP version:
PHP 7.4.20 (cli) (built: Jun 28 2021 22:14:08) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans
imagick version:
/var/www/html # php -i | grep imagick
/usr/local/etc/php/conf.d/docker-php-ext-imagick.ini,
imagick
imagick module => enabled
imagick module version => 3.5.1
imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
imagick.allow_zero_dimension_images => 0 => 0
imagick.locale_fix => 0 => 0
imagick.progress_monitor => 0 => 0
imagick.set_single_thread => 1 => 1
imagick.shutdown_sleep_count => 10 => 10
imagick.skip_version_check => 0 => 0
Relevant php code:
$img = new \Imagick();
$img->setResolution(300, 380);
$img->readImage($img2Fake);
$img->setFormat('png24');
$bg = new \Imagick();
$bg->newImage(300, 380, new \ImagickPixel('#ffffff'));
$draw = new \ImagickDraw();
$draw->setFillColor(new \ImagickPixel("#ede717"));
$draw->setStrokeColor(new \ImagickPixel('#ede717'));
$bgx2 = 63.5 * (float)$avgRating;
$draw->rectangle(24, 0, $bgx2, 380);
$bg->drawImage($draw);
$bg->compositeImage($img, \Imagick::COMPOSITE_OVER, 0, 0);
$bg->setImageFormat('jpg');
$strDraw = new \ImagickDraw();
$strDraw->setFillColor(new \ImagickPixel('#555'));
$strDraw->setTextAlignment(\Imagick::ALIGN_CENTER);
$strDraw->setFontSize('32');
$strDraw->setFontWeight(900);
$strDraw->annotation(150, 135, $ratingText);
$strDraw->setFontSize('20');
$strDraw->setFontWeight(200);
$strDraw->annotation(150, 168, $avgRating . ' / 5,0');
$strDraw->setFontSize('18');
$strDraw->setFontWeight(200);
$strDraw->annotation(150, 194, number_format($count, 0, ',', '.') . ' Bewertungen');
$bg->drawImage($strDraw);
Exception:
ImagickException: non-conforming drawing primitive definition `text' @ error/draw.c/RenderMVGContent/4469
#6 /var/www/html/src/pp/WidgetBundle/Lib/WidgetRenderer.php(95): Imagick::drawimage
#5 /var/www/html/src/pp/WidgetBundle/Lib/WidgetRenderer.php(95): pp\WidgetBundle\Lib\WidgetRenderer::renderWidget
#4 /var/www/html/src/pp/WidgetBundle/Controller/DefaultController.php(30): pp\WidgetBundle\Controller\DefaultController::renderAction
#3 /var/www/html/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php(151): Symfony\Component\HttpKernel\HttpKernel::handleRaw
#2 /var/www/html/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel::handle
#1 /var/www/html/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(200): Symfony\Component\HttpKernel\Kernel::handle
#0 /app.php(162): null
Relevant Dockerfile part:
FROM registry.var-lab.com/php/php:7.4.20-fpm-alpine
...
RUN set -ex \
&& 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.5.1 \
&& docker-php-ext-enable imagick \
&& apk add --no-cache --virtual .imagick-runtime-deps imagemagick \
&& apk del .phpize-deps
It has worked without using docker, but with the same PHP version "directy" installed on an Ubuntu 16.x machine.
Hi, can you try:
i. List the fonts returned by Imagick::queryFonts()
to see if there any fonts configured.
ii. Explicitly set a font, either one listed from above, or a TTF file you acquire from somewhere.
This error message (which is not great) seems to happen when a default font isn't available.
Thanks for your reply @Danack. Can you say which one the default font is?
Imagick::queryFonts()
outputs an empty array.
It works now, after adding the following line to the Dockerfile:
RUN apk add --no-cache msttcorefonts-installer && update-ms-fonts && fc-cache -f
I think either Arial or Helvetica.
I'm beginning to think though that relying on system fonts is a 'not great' way of managing fonts, and explicitly packaging the fonts you want to use might be better.
At least a more descriptive error message would be very helpful!
Going to change this back to open so people see it, and remind myself to do something about it.
Explicitly set a font, either one listed from above, or a TTF file you acquire from somewhere.
How do I do this?
I have a TTF font and don't want to install the entire msttcorefonts-installer
Using Wand, Python and Docker.