Tuesday, November 19, 2024
Google search engine
HomeLanguagesPHP | Imagick setImageCompressionQuality() Function

PHP | Imagick setImageCompressionQuality() Function

The Imagick::setImageCompressionQuality() function is an inbuilt function in PHP which is used to set the image compression quality.

Syntax:

bool Imagick::setCompressionQuality( int $quality )

Parameters: This function accepts single parameter $quality which holds an integer value representing image compression quality.

Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

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

Program 1:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Set the Compression quality
$imagick->setImageCompressionQuality(26);
  
// Get the Compression quality
$compressionQuality = $imagick->getImageCompressionQuality();
echo $compressionQuality;
?>


Output:

26

Program 2:




<?php
  
// Create a new imagick object
$imagick = new Imagick(
  
// Set the Compression quality
$imagick->setImageCompressionQuality(1);
  
// Show the output
$imagick->setformat('jpg');
header("Content-Type: image/jpg");
echo $imagick->getImageBlob();
?>


Output:

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

RELATED ARTICLES

Most Popular

Recent Comments