Wednesday, July 3, 2024
HomeLanguagesPhpPHP | Gmagick compositeimage() Function

PHP | Gmagick compositeimage() Function

The Gmagick::compositeimage() function is an inbuilt function in PHP which is used to composite one image onto another at the specified offset. Offset is actually the distance from where to start compositing the second image.

Syntax:

Gmagick Gmagick::compositeimage( Gmagick $source, int $COMPOSE, int $x, int $y )

Parameters: This function accepts four parameters as mentioned above and described below:

  • $source: It specifies the source of image to composite with another image.
  • $compose: It specifies the type of composition to apply.
  • $x: It specifies the x-coordinate.
  • $y: It specifies the y-coordinate.

Return Value: This function returns a Gmagick object containing the composite image.

Exceptions: This function throws GmagickException on error.

Below programs illustrate the Gmagick::compositeimage() function in PHP:

Program 1: This program uses Gmagick::compositeimage() function to composite two images with no offset.




<?php
  
// Create two new Gmagick object
$gmagick1 = new Gmagick(
  
$gmagick2 = new Gmagick(
  
// Composite the images with no offset
$gmagick1->compositeimage($gmagick2,
          Gmagick::COMPOSITE_MULTIPLY, 0, 0);
  
// Output the image  
header('Content-type: image/png');  
echo $gmagick1;  
?>


Output:

Program 2: This program uses Gmagick::compositeimage() function to composite two image with offset.




<?php
  
// Create two new Gmagick object
$gmagick1 = new Gmagick(
  
$gmagick2 = new Gmagick(
  
// Composite the images with offset
$gmagick1->compositeimage($gmagick2,
         Gmagick::COMPOSITE_OVER, 300, 0);
  
// Output the image  
header('Content-type: image/png');  
echo $gmagick1;  
?>  


Output:

Reference: https://www.php.net/manual/en/gmagick.compositeimage.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!

Nicole Veronica Rubhabha
Nicole Veronica Rubhabha
A highly competent and organized individual DotNet developer with a track record of architecting and developing web client-server applications. Recognized as a personable, dedicated performer who demonstrates innovation, communication, and teamwork to ensure quality and timely project completion. Expertise in C#, ASP.Net, MVC, LINQ, EF 6, Web Services, SQL Server, MySql, Web development,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments