Page 1 of 1

automatically edit user-chosen images

Posted: 2015-08-31T01:34:27-07:00
by cinder
Hey,

I've created an app, that lets the user select an image. Afterwards its resized and cropped with imagemagick.
Is there a way to alway have the same quality after resizing as the original image had?

Here's my code:

Code: Select all

$img->setImageFormat('jpg');
$img->setImageCompression(Imagick::COMPRESSION_JPEG);
$img->setImageCompressionQuality(100); 
    
$profiles = $img->getImageProfiles("icc", true);

$img->stripImage();

if(!empty($profiles))
{
	$img->profileImage("icc", $profiles['icc']);
}
    
    
list($width_orig, $height_orig) = getimagesize($origPath);
    
if($width_orig >= $height_orig)
{
	//fix rounding problem if necessary
	$xPos = (($xPos-1) + $targ_w == $_SESSION["xPos2"])?$xPos-1:$xPos;
                    
	$img->resizeImage ( 0, $targ_h,  Imagick::FILTER_LANCZOS, 1);
	$img->unsharpMaskImage(0 , 0.5 , 1 , 0.05); 
	$img->cropImage($targ_w, $targ_h, $xPos, 0);
                    
}

Thanks for the help

Re: automatically edit user-chosen images

Posted: 2015-08-31T09:42:26-07:00
by fmw42
I believe if you leave off the

$img->setImageCompressionQuality(100);

Imagemagick will try to detect the quality setting in the input and use it. If it fails to detect it, then it assigns the default 92. see http://www.imagemagick.org/script/comma ... hp#quality

You could also detect the input quality your self from the verbose information and reassign it in your processing