PHP | Imagick current() Function

The Imagick::current() function is an inbuilt function in PHP which is used to return the reference of current Imagick object. This function does not create any copy but returns the same instance of Imagick.

Syntax:

Imagick Imagick::current( void )

Parameters: This function does not accepts any parameters.



Return Value: It returns the instance of Imagick object.

Program 1: This program is regarding the simple functioning of the current() method. It will create a variable with a new name pointing to the same instance and show the content of the old one with the help of the new.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create new Imagick object
$im = new Imagick(
  
// Use Imagick::current() function and
// initialized with Image 
$im1 = $im->current();
  
// Imagick instance returned in a new variable $im1
header("Content-type: image/png");
  
// Display image as output
echo $im1;
  
?>

chevron_right


Output:
Output

Program 2: It performs the blur operation on the image using the 2nd variable and the change will be reflected on the first one as both of them are pointing to the same instance.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
   
// Create new Imagick object
$im = new Imagick(
   
// Use Imagick::current() function
$im1 = $im->current();
   
// Use Imagick::blurImage() function to blur the image
$im1->blurImage(5, 3);
  
header("Content-type: image/png");
   
// Display the image as
echo $im;
   
?>

chevron_right


Output:
Output 2

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



My Personal Notes arrow_drop_up

Im a final year MCA student at Panjab University, Chandigarh, one of the most prestigious university of India I am skilled in various aspects related to Web Development and AI I have worked as a freelancer at upwork and thus have knowledge on various aspects related to NLP, image processing and web

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.