I need help. I try to use imagecropauto(), but PNG still getting black background. Here is the code:
$im = imagecreatefrompng($imgPath);
imagealphablending($im, false);
imagesavealpha($im, true);
// if imagepng($im...) called here, original PNG is saved with transparency
// if I use IMG_CROP_TRANSPARENT - crop doesn't works
// IMG_CROP_SIDES working how I expect
$cropped = imagecropauto($im, IMG_CROP_SIDES);
if ($cropped !== false) {
// destroy old image
imagedestroy($im);
imagealphablending($cropped, false);
imagesavealpha($cropped, true);
// save cropped image with black background
imagepng($cropped, $imgPath);
imagedestroy($cropped);
}
Any suggestion what's wrong?
EDIT: PNG image is transparent by alpha channel on points, so some points have lower opacity then other. If I use imagealphablending - true (default) I can only set one color to be transparent and result has black line around picture.