Thursday, September 4, 2025
HomeLanguagesPHP | Imagick newImage() Function

PHP | Imagick newImage() Function

The Imagick::newImage() function is an inbuilt function in PHP which is used to creates a new image. This function creates a new image and associates ImagickPixel value as the background color.

Syntax: 

bool Imagick::newImage( $cols, $rows, $background, $format )

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

  • $cols: This parameter is used to set the column of image.
  • $rows: This parameter is used to set the row of image.
  • $background: This parameter is used to set the background color of image.
  • $format: This parameter is used to define the image format.

Return Value: This function returns True on success.
Errors/Exceptions: This function throws ImagickException on error.

Below program illustrates the Imagick::newImage() function in PHP:

Program:  

PHP




<?php
 
// Create an Imagick object
$image = new Imagick();
 
// Use newImage function to create new image
$image->newImage(650, 400, new ImagickPixel('green'));
 
// Set the image format
$image->setImageFormat('png');
 
header('Content-type: image/png');
 
// Display the output image
echo $image;
?>


Output: 

Reference: http://php.net/manual/en/imagick.newimage.php
 

RELATED ARTICLES

Most Popular

Dominic
32260 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6625 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6694 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS