PHP | ImagickDraw pathLineToHorizontalRelative() Function

The ImagickDraw::pathLineToHorizontalRelative() function is an inbuilt function in PHP which is used to draw a horizontal line path from the current point to the target point using relative coordinates. The target point then becomes the new current point.
Syntax:
bool ImagickDraw::pathLineToHorizontalRelative( float $x )
Parameters:This function accepts a single parameter $x which holds the x-coordinate.
Return Value: This function returns TRUE on success.
Exceptions: This function throws ImagickException on error.
Below given programs illustrate the ImagickDraw::pathLineToHorizontalRelative() function in PHP:
Program 1:
<?php // Create a new imagick object $imagick = new Imagick(); // Create a image on imagick object $imagick->newImage(800, 250, 'white'); // Create a new ImagickDraw object $draw = new ImagickDraw(); // Set the stroke color $draw->setStrokeColor('Green'); // Set the stroke width $draw->setStrokeWidth(5); // Draw line using pathLineToHorizontalRelative $draw->pathStart(); $draw->pathMoveToRelative(0, 100); $draw->pathLineToHorizontalRelative(1000); $draw->pathFinish(); // Render the draw commands $imagick->drawImage($draw); // Show the output $imagick->setImageFormat('png'); header("Content-Type: image/png"); echo $imagick->getImageBlob(); ?> |
Output:
Program 2:
<?php // Create a new imagick object $imagick = new Imagick(); // Create a image on imagick object $imagick->newImage(800, 250, 'white'); // Create a new ImagickDraw object $draw = new ImagickDraw(); $color = ['blue', 'red', 'green', 'yellow', 'orange', 'brown', 'pink']; // Set the stroke width $draw->setStrokeWidth(5); // Draw lines for ($x = 0; $x < 7; $x++) { $draw->setStrokeColor($color[$x]); $draw->pathStart(); $draw->pathMoveToRelative(0, $x * 40); $draw->pathLineToHorizontalRelative(800); $draw->pathFinish(); } // Render the draw commands $imagick->drawImage($draw); // Show the output $imagick->setImageFormat('png'); header("Content-Type: image/png"); echo $imagick->getImageBlob(); ?> |
Output:
Reference: https://www.php.net/manual/en/imagickdraw.pathlinetohorizontalrelative.php
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!




