|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-05-27 16:06 UTC] lee dot traynor at skeptic dot de
Description: ------------ --- From manual page: http://www.php.net/imagickdraw.polyline --- Under certain irregular conditions the ImagickDraw function polyline produces a closed polygon, identical to function polygon. I have noticed that I can draw lines with stroke width of up to 2 pixels and they remain open, but on changing the stroke width to anything > 2 the line closes. Test script: --------------- // $pc is an array of several hundred coordinates of the form [['x'=>1, 'y'=>1], ['x'=>2, 'y'=>4]...] $im = new Imagick (); $im->newImage (1000, 1500, "white"); $draw = new ImagickDraw (); $draw->setStrokeWidth (2); $draw->polyline ($pc); $im->drawImage ($draw); // OK Changing the value in setStrokeWidth to > 2 closes the polygon Workaround is to reverse the original array and append it to the end of the original array, i.e. to trace back over the polyline to avoid closing it. $pc = array_merge ($pc, array_reverse ($pc)); // draws an open polyline PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 18:00:01 2025 UTC |
> If this occurs, it would be nice if I could see what the draw object contains Extending the class to be able to log this type of thing, is usually better than relying on internal logging. Here is an approximation of one way of doing that. class ImagickDrawLogging extends ImagickDraw { static public $recordedCoordinates = []; public function polyline ( array $coordinates ) { self::$recordedCoordinates[] = $coordinates; parent::polyline($coordinates); } public static function logInfo() { if (count(self::$recordedCoordinates) == 0) { return; } $temp_file = tempnam(sys_get_temp_dir(), 'poly_debug'); file_put_contents($temp_file, var_export(self::$recordedCoordinates, true)); } } // Put this at the start of your program $debug_imagick_draw = random_int(1, 100); if ($debug_imagick_draw <= 3) { // only log 3% of requests class_alias('ImagickDrawLogging', 'ImagickDrawDebug'); } else { class_alias('ImagickDraw', 'ImagickDrawDebug'); } // Put this at the end of your program \ImagickDrawLogging::logInfo(); And change ImagickDraw => ImagickDrawDebug for the place where you're going to be calling polyline. That will record the ImagickDraw polyline calls for a small percentage of users. Obviously, if you're testing in dev, you could enable that for all requests.Without more information, this is impossible to investigate. I failed to find a problem using this test script. ------------------- <?php $pc = []; $pc[] = ['x' => 50, 'y' => 50]; for ($i=0; $i<400; $i++) { $pc[] = ['x' => 500 + rand(0, 500), 'y' => 50 + rand(0, 500)]; } $pc[] = ['x' => 50, 'y' => 400]; $im = new Imagick (); $im->newImage (1000, 1000, "white"); $draw = new ImagickDraw (); $draw->setStrokeWidth(5); $draw->setStrokeColor('rgb(0, 0, 0)'); $draw->setFillColor('DodgerBlue2'); $draw->polyline ($pc); $im->drawImage ($draw); // OK $im->setImageFormat('png'); $im->writeImage('output.png');