0

I am using PHP ImageMagic and I am trying to put a border around a Rectangle. I am following this, and this to create the border. It seems to be working fine for them, but for me, if I make the stroke width more than 2, it starts to break.

Here is the code, that I am using

$white = new ImagickPixel("rgb(255, 255, 255)");
$borderWidth = 10;

$draw = new ImagickDraw();
$strokeColor = new ImagickPixel("rgb(255, 255, 255)");
$fillColor = new ImagickPixel("none");

$draw->setStrokeColor($strokeColor);
$draw->setFillColor($fillColor);
//$draw->setStrokeOpacity(1);
$draw->setStrokeWidth(2);

$draw->rectangle(5, 5, 295, 295);
$imagick = new Imagick();
$imagick->newImage(300, 300, "rgb(225, 225, 225)");
$imagick->setImageFormat("png");

$imagick->drawImage($draw);
header("Content-type:image/png");
echo $imagick;die;

This is the result, with $draw->setStrokeWidth(2)

enter image description here

And this is the result, with $draw->setStrokeWidth(5) which obviously seems broken.

enter image description here

What might be the issue?

Community
  • 1
  • 1
Parthapratim Neog
  • 4,352
  • 6
  • 43
  • 79
  • I would guess it could be a calculation problem as stroke is on the outside and you are starting at 5. Does $draw->setStrokeWidth(4) work? – Bonzo Jul 05 '16 at 11:36
  • Nope @Bonzo, I checked Several values, only `1` and `2` seems to work. – Parthapratim Neog Jul 05 '16 at 11:46
  • Just tried it on my server and it works OK with $draw->setStrokeWidth(5); of course it is not equal on the background as you need to change this line $draw->rectangle(5, 5, 290, 290); – Bonzo Jul 05 '16 at 16:21
  • It looks like a bug in the version of ImageMagick installed on your system. Please can you say what version of ImageMagick it is, and then try upgrading it? You will also need to re-install or recompile Imagick. – Danack Jul 05 '16 at 23:00

0 Answers0