When I try to crop transparant area of an image, its get to keep it original size, and the transparant areas are turned black.
If i run this code:
<?php
// Create a 300x300px transparant image with a 100px wide red circle in the middle
$i = imagecreatetruecolor(300, 300);
imagealphablending($i, FALSE);
imagesavealpha($i, TRUE);
$transparant = imagecolorallocatealpha($i, 0xDD, 0xDD, 0xDD, 0x7F);
imagefill($i, 0, 0, $transparant);
$red = imagecolorallocate($i, 0xFF, 0x0, 0x0);
imagefilledellipse($i, 150, 150, 100, 100, $red);
imagepng($i, "red_300.png");
// Crop away transparant parts and save
$i2 = imagecropauto($i, IMG_CROP_TRANSPARENT);
imagepng($i2, "red_crop_trans.png");
imagedestroy($i2);
// Crop away bg-color parts and save
$i2 = imagecropauto($i, IMG_CROP_SIDES);
imagepng($i2, "red_crop_sides.png");
imagedestroy($i2);
// clean up org image
imagedestroy($i);
I end up with a red_crop_trans.png
image that is a 300x300px
black image with an 100x100px
red circle in it.
And a red_crop_sides.png that is a 100x100px
black image with a 100x100px
red circle in it.
Why is red_crop_trans.png not croped to 100x100px
? and why is the background of both images black? And how do I crop them while keeping the transparace?