The color value (3rd argument) for transparency is "none".(PECL imagick 2, PECL imagick 3)
Imagick::newImage β Π‘ΠΎΠ·Π΄Π°ΡΡ Π½ΠΎΠ²ΠΎΠ΅ ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΠ΅
$cols,$rows,$background,$format = ?Π‘ΠΎΠ·Π΄Π°ΡΡ Π½ΠΎΠ²ΠΎΠ΅ ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΠ΅ ΠΈ ΡΠ²ΡΠ·ΡΠ²Π°Π΅Ρ Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅ ImagickPixel Π² ΠΊΠ°ΡΠ΅ΡΡΠ²Π΅ ΡΠ²Π΅ΡΠ° ΡΠΎΠ½Π°
colsΠ‘ΡΠΎΠ»Π±ΡΡ Π² Π½ΠΎΠ²ΠΎΠΌ ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΠΈ
rowsΠ‘ΡΡΠΎΠΊΠΈ Π² Π½ΠΎΠ²ΠΎΠΌ ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΠΈ
backgroundΠ¦Π²Π΅Ρ ΡΠΎΠ½Π°, ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅ΠΌΡΠΉ Π΄Π»Ρ ΡΡΠΎΠ³ΠΎ ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΡ
formatΠ€ΠΎΡΠΌΠ°Ρ ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΡ. ΠΡΠΎΡ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡ Π±ΡΠ» Π΄ΠΎΠ±Π°Π²Π»Π΅Π½ Π² Imagick Π²Π΅ΡΡΠΈΠΈ 2.0.1.
Π€ΡΠ½ΠΊΡΠΈΡ Π² ΡΠ»ΡΡΠ°Π΅ ΡΡΠΏΠ΅ΡΠ½ΠΎΠΉ ΡΠ°Π±ΠΎΡΡ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅Ρ true.
Π€ΡΠ½ΠΊΡΠΈΡ Π²ΡΠ±ΡΠ°ΡΡΠ²Π°Π΅Ρ ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ ImagickException, Π΅ΡΠ»ΠΈ Π²ΠΎΠ·Π½ΠΈΠΊΠ»Π° ΠΎΡΠΈΠ±ΠΊΠ°.
| ΠΠ΅ΡΡΠΈΡ | ΠΠΏΠΈΡΠ°Π½ΠΈΠ΅ |
|---|---|
| PECL imagick 2.1.0 | Π’Π΅ΠΏΠ΅ΡΡ Π΄ΠΎΠΏΡΡΠΊΠ°Π΅ΡΡΡ ΡΡΡΠΎΠΊΠ°, ΠΏΡΠ΅Π΄ΡΡΠ°Π²Π»ΡΡΡΠ°Ρ ΡΠ²Π΅Ρ, Π² ΠΊΠ°ΡΠ΅ΡΡΠ²Π΅ ΡΡΠ΅ΡΡΠ΅Π³ΠΎ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΠ°. Π Π°Π½Π΅Π΅ Π΄ΠΎΠΏΡΡΠΊΠ°Π»ΡΡ ΡΠΎΠ»ΡΠΊΠΎ ΠΎΠ±ΡΠ΅ΠΊΡ ImagickPixel. |
ΠΡΠΈΠΌΠ΅Ρ #1 ΠΡΠΈΠΌΠ΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΡ Imagick::newImage():
Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ Π½ΠΎΠ²ΠΎΠ³ΠΎ ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΡ ΠΈ Π΅Π³ΠΎ ΠΎΡΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΠ΅.
<?php
$image = new Imagick();
$image->newImage(100, 100, new ImagickPixel('red'));
$image->setImageFormat('png');
header('Content-type: image/png');
echo $image;
?>The color value (3rd argument) for transparency is "none".As it isn't obvious, the cols and rows arguments correspond to the width and height of the new image, expressed in pixels. Example #1 would generate a 100 pixel by 100 pixel image.It's not obvious and may be related only to some specific versions of ImageMagick (tested only for 6.7.7 and 6.8.9), but $cols and $rows must be a positive non-zero value.
<?php
$image = new Imagick();
$image->newImage(0, 100, new ImagickPixel('red'));
$image->setImageFormat('png');
file_put_contents('image.png', $image);
?>
In this case imagemagick will crash without throwing any exception and you'll get something along the lines (in your apache error log or console output):
unable to acquire cache view `No such file or directory' @ fatal/cache-view.c/AcquireAuthenticCacheView/121.
This might be the case when you calculate $cols and $rows (say, based on user input and predefined target image DPI):
<?php
$image = new Imagick();
$img->newImage($userInput->getWidth() * $defaultPpi, $userInput->getHeight() * $defaultPpi, new ImagickPixel('white'));
?>
In this case if user requested image with 0.006 width (in inches), the code would work for $defaultPpi = 300 ppi, but would crash for
$defaultPpi = 72 ppi