Voting

: seven minus zero?
(Example: nine)

The Note You're Voting On

petr dot biza at gmail dot com
15 years ago
There is function to crop blank edges from image.

<?php
/**
* $image image cursor (from imagecreatetruecolor)
* $backgound image curosr (from imagecolorallocate)
* $paddng int
*/
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 there match
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++;

// create new image with padding
$img = imagecreatetruecolor($right-$left+$padding*2,$bottom-$top+$padding*2);
// fill the background
imagefill($img, 0, 0, $background);
// copy
imagecopy($img, $image, $padding, $padding, $left, $top, $right-$left, $bottom-$top);

// destroy old image cursor
imagedestroy($image);
return
$img;
}
?>

<< Back to user notes page

To Top