PHP | Imagick setSamplingFactors() Function
Last Updated :
25 Aug, 2021
The Imagick::setSamplingFactors() function is an inbuilt function in PHP which is used to set the image sampling factors.
Syntax:
bool Imagick::setSamplingFactors( array $factors )
Parameters: This function accepts a single parameter $factors which holds an associative array containing sampling factors.
Return Value: This function returns TRUE on success.
Exceptions: This function throws ImagickException on error.
Below given programs illustrate the Imagick::setSamplingFactors() function in PHP:
Program 1:
PHP
<?php
$imagick = new Imagick(
$imagick ->setSamplingFactors( array ( '6' , '7' , '8' ));
$samplingFactors = $imagick ->getSamplingFactors();
print ( "<pre>" .print_r( $samplingFactors , true). "</pre>" );
?>
|
Output:
Array
(
[0] => 6
[1] => 7
[2] => 8
)
Program 2:
PHP
<?php
$imagick = new Imagick(
$imagick ->setImageFormat( 'jpg' );
$imagick ->setSamplingFactors( array ( '1x1' , '2x2' ));
$compressed = $imagick ->getImageBlob();
$reopen = new Imagick();
$reopen ->readImageBlob( $compressed );
$reopen ->resizeImage(667, 184, 0, 1);
header( "Content-Type: image/jpg" );
echo $reopen ->getImageBlob();
?>
|
Output:
Reference: https://www.php.net/manual/en/imagick.setsamplingfactors.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...