così è più veloce
Codice PHP:
<?php
$image = imagecreatefrompng("ada.png");
$arr = getimagesize("ada.png");
$width = $arr[0];
$height = $arr[1];
//top
for($y = 0; $y < $height; $y++)
{
for($x = 0; $x < $width; $x++)
{
if(imagecolorat($image, $x ,$y) != 16777215 ){
$top=$y;
$x=$width;$y=$height;
}
}
}
//Bottom
for($y = $height-1; $y > 0; $y--)
{
for($x = 0; $x < $width; $x++)
{
if(imagecolorat($image, $x ,$y) != 16777215 ){
$bottom=$y+1;
$x=$width;$y=0;
}
}
}
//Left
for($x = 0; $x < $width; $x++)
{
for($y = $top; $y < $bottom; $y++)
{
if(imagecolorat($image, $x ,$y) != 16777215 ){
$left=$x;
$x=$width;$y=$height;
}
}
}
//Right
for($x = $width-1; $x > $left; $x--)
{
for($y = $top; $y < $bottom; $y++)
{
if(imagecolorat($image, $x ,$y) != 16777215 ){
$right=$x+1;
$x=0;$y=$height;
}
}
}
$newwidth = $right-$left;
$newheight = $bottom-$top;
// Content type
header('Content-type: image/jpeg');
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
// Resize
imagecopyresized ($thumb, $image, 0, 0, $left , $top , $newwidth, $newheight, $newwidth, $newheight);
// Output
imagepng($thumb);
?>
:quote: