There is function to crop blank edges from image.
<?php
function imageCrop($image, $background = false, $padding = 0) {
if($background)
$background = imagecolorallocate($image, 255, 255, 255);
$top = imageSY($image);
$left = imageSX($image);
$bottom = 0;
$right = 0;
for ($x = 0 ; $x < imagesx($image) ; $x++) {
for ($y = 0 ; $y < imagesy($image) ; $y++) {
if(imagecolorat($image, $x, $y) != $background) {
if($x < $left)
$left = $x;
if($x > $right)
$right = $x;
if($y > $bottom)
$bottom = $y;
if($y < $top)
$top = $y;
}
}
}
$right++;
$bottom++;
$img = imagecreatetruecolor($right-$left+$padding*2,$bottom-$top+$padding*2);
imagefill($img, 0, 0, $background);
imagecopy($img, $image, $padding, $padding, $left, $top, $right-$left, $bottom-$top);
imagedestroy($image);
return $img;
}
?>