Open In App

PHP | ImagickDraw pathLineToHorizontalAbsolute() Function

Improve
Improve
Like Article
Like
Save
Share
Report

The ImagickDraw::pathLineToHorizontalAbsolute() 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 absolute coordinates. The target point then becomes the new current point. The current point can also be alternatively set with pathMoveToRelative() function.

Syntax:

bool ImagickDraw::pathLineToHorizontalAbsolute( 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::pathLineToHorizontalAbsolute() 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('blue');
  
// Set the stroke width
$draw->setStrokeWidth(5);
  
// Draw line using pathLineToHorizontalAbsolute
$draw->pathStart();
$draw->pathMoveToRelative(0, 100);
$draw->pathLineToHorizontalAbsolute(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();
  
// Set the stroke color
$draw->setStrokeColor('black');
  
// Set the stroke width
$draw->setStrokeWidth(5);
   
// Draw lines
$draw->pathStart();
for($x = 0; $x < 15; $x++) {
    $draw->pathMoveToRelative(0, 20);
    if($x % 2) {
        $draw->pathLineToHorizontalAbsolute(0);
    } else {
        $draw->pathLineToHorizontalAbsolute(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:

Reference: https://www.php.net/manual/en/imagickdraw.pathlinetohorizontalabsolute.php



Last Updated : 23 Dec, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads