lexxai
lexxai

Reputation: 85

php imagemagic crop resize crop result is image 1x1

Try crop image resize and crop again by this code:

$im = new Imagick($file_name);
$result=$im->cropImage($w,$h,$x,$y);
$result=$im->resizeImage($nw, $nh, $resizefilter, 1,true);
$result=$im->cropImage($nw,$nh,$x,$y);
$iw=$im->getImageWidth();
$ih=$im->getImageHeight();

But at result have wrong image ($im) size $iw,$ih is 1x1px.

After different combinations found solution, after resizeImage() insert thumbnailImage() with same size:

$im = new Imagick($file_name);
$result=$im->cropImage($w,$h,$x,$y);
$result=$im->resizeImage($nw, $nh, $resizefilter, 1,true);
$result=$im->thumbnailImage($nw,$nh);
$result=$im->cropImage($nw,$nh,$x,$y);
$iw=$im->getImageWidth();
$ih=$im->getImageHeight();

Why it work? May be other solution is ?

Upvotes: 1

Views: 194

Answers (1)

lexxai
lexxai

Reputation: 85

Solution:

$im = new Imagick($file_name);
$result=$im->cropImage($w,$h,$x,$y);
$result=$im->setImagePage($w,$h,0,0);
$result=$im->resizeImage($nw, $nh, $resizefilter, 1,true);
$result=$im->cropImage($nw,$nh,$x,$y);
$result=$im->setImagePage($nw,$nh,0,0);
$iw=$im->getImageWidth();
$ih=$im->getImageHeight();

Upvotes: 1

Related Questions