From 0750ec93395c5605456585937e1febfcd51c0907 Mon Sep 17 00:00:00 2001 From: cytopia Date: Thu, 21 Nov 2019 17:22:36 +0100 Subject: [PATCH] imagick integration tests --- .../imagick/{imagick.php => imagick-png.php} | 5 +- tests/mods/modules/imagick/imagick-webp.php | 59 +++++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) rename tests/mods/modules/imagick/{imagick.php => imagick-png.php} (94%) create mode 100644 tests/mods/modules/imagick/imagick-webp.php diff --git a/tests/mods/modules/imagick/imagick.php b/tests/mods/modules/imagick/imagick-png.php similarity index 94% rename from tests/mods/modules/imagick/imagick.php rename to tests/mods/modules/imagick/imagick-png.php index c40ead04..cdc3b04e 100644 --- a/tests/mods/modules/imagick/imagick.php +++ b/tests/mods/modules/imagick/imagick-png.php @@ -27,7 +27,7 @@ $img = new Imagick(); if ($img->newImage($width, $height, new ImagickPixel('transparent')) !== TRUE) { - echo 'FAIL: imagecreatetruecolor()'; + echo 'FAIL: newImage()'; exit(1); } @@ -44,9 +44,8 @@ $draw->setFillColor('black'); if ($img->setImageFormat('png') !== TRUE) { - echo 'FAIL: imagecreatetruecolor()'; + echo 'FAIL: setImageFormat()'; exit(1); } - echo 'OK'; diff --git a/tests/mods/modules/imagick/imagick-webp.php b/tests/mods/modules/imagick/imagick-webp.php new file mode 100644 index 00000000..825e0b06 --- /dev/null +++ b/tests/mods/modules/imagick/imagick-webp.php @@ -0,0 +1,59 @@ +=')) { + echo 'OK'; + exit(0); +} + +/* Set width and height in proportion of genuine PHP logo */ +$width = 400; +$height = 210; + +/* Create an Imagick object with transparent canvas */ +$img = new Imagick(); + +if ($img->newImage($width, $height, new ImagickPixel('transparent')) !== TRUE) { + echo 'FAIL: newImage()'; + exit(1); +} + +/* New ImagickDraw instance for ellipse draw */ +$draw = new ImagickDraw(); +/* Set purple fill color for ellipse */ +$draw->setFillColor('#777bb4'); +/* Set ellipse dimensions */ +$draw->ellipse($width / 2, $height / 2, $width / 2, $height / 2, 0, 360); +/* Draw ellipse onto the canvas */ +$img->drawImage($draw); + +/* Reset fill color from purple to black for text (note: we are reusing ImagickDraw object) */ +$draw->setFillColor('black'); + +if ($img->setImageFormat('webp') !== TRUE) { + echo 'FAIL: setImageFormat()'; + exit(1); +} +if ($img->setImageAlphaChannel(imagick::ALPHACHANNEL_ACTIVATE) !== TRUE) { + echo 'FAIL: setImageAlphaChannel()'; + exit(1); +} +if ($img->setBackgroundColor(new ImagickPixel('transparent')) !== TRUE) { + echo 'FAIL: setBackgroundColor()'; + exit(1); +} + +echo 'OK';