Thursday, December 18, 2025
HomeLanguagesPHP | Imagick setImageFilename() Function

PHP | Imagick setImageFilename() Function

The Imagick::setImageFilename() function is an inbuilt function in PHP which is used to set the filename of a particular image.

Syntax:

bool Imagick::setImageFilename( string $filename )

Parameters: This function accepts single parameter $filename which holds a string that represent the filename.

Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

Below programs illustrate the Imagick::setImageFilename() function in PHP:

Program 1:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Set the Filename
$imagick->setImageFilename('myNewFilename.png');
  
// Get the Filename
$name = $imagick->getImageFilename();
echo $name;
?>


Output:

myNewFilename.png

Program 2:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Set the Filename
$imagick->setImageFilename('myAnotherNewFilename.png');
  
// Get the Filename
$name = $imagick->getImageFileName();
  
// Write the image to same folder
$imagick->writeImage($name);
?>


Output:

This program creates a file called myAnotherNewFilename.png in the same folder. 

Reference: https://www.php.net/manual/en/imagick.setimagefilename.php

RELATED ARTICLES

Most Popular

Dominic
32455 POSTS0 COMMENTS
Milvus
108 POSTS0 COMMENTS
Nango Kala
6823 POSTS0 COMMENTS
Nicole Veronica
11958 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12037 POSTS0 COMMENTS
Shaida Kate Naidoo
6958 POSTS0 COMMENTS
Ted Musemwa
7203 POSTS0 COMMENTS
Thapelo Manthata
6911 POSTS0 COMMENTS
Umr Jansen
6890 POSTS0 COMMENTS