note 97836 added to function.imagecopy

From: Date: Tue, 11 May 2010 14:23:00 +0000
Subject: note 97836 added to function.imagecopy
Groups: php.notes 
Request: Send a blank email to php-notes+get-169145@lists.php.net to get a copy of this message
There is function to crop blank edges from image. /** * $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; } ---- Server IP: 147.32.160.17 Probable Submitter: 89.29.90.77 ---- Manual Page -- http://www.php.net/manual/en/function.imagecopy.php Edit -- https://master.php.net/note/edit/97836 Del: integrated -- https://master.php.net/note/delete/97836/integrated Del: useless -- https://master.php.net/note/delete/97836/useless Del: bad code -- https://master.php.net/note/delete/97836/bad+code Del: spam -- https://master.php.net/note/delete/97836/spam Del: non-english -- https://master.php.net/note/delete/97836/non-english Del: in docs -- https://master.php.net/note/delete/97836/in+docs Del: other reasons-- https://master.php.net/note/delete/97836 Reject -- https://master.php.net/note/reject/97836 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#169145) next »