note 118677 added to function.imagettfbbox
| From: | gw at example dot com | Date: | Mon, 18 Jan 2016 17:32:34 +0000 |
| Subject: | note 118677 added to function.imagettfbbox | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204710@lists.php.net to get a copy of this message | ||
a little something to replace in blackbart tip :
// start scanning (0=> black => empty)
$rleft = $w4 = $width<<2;
$rright = 0;
$rbottom = 0;
$rtop = $h4 = $height<<2;
for( $x = 0; $x < $w4; $x++ )
for( $y = 0; $y < $h4; $y++ )
if( imagecolorat( $img, $x, $y ) ){
$rleft = min( $rleft, $x );
$rright = max( $rright, $x );
$rtop = min( $rtop, $y );
$rbottom = max( $rbottom, $y );
}
with
// start scanning (0=> black => empty)
$break = false;
$rleft = $w4 = $width<<2;
$rright = 0;
$rbottom = 0;
$rtop = $h4 = $height<<2;
// scanning from left to right, breaking when a pixel is found, to scan from the other side :
avoid scanning all pixels !
for($x=0; $x<$w4; $x++){
for($y=0; $y<$h4; $y++)
if(imagecolorat($img,$x,$y)){
$rtop = min($rtop, $y); $rleft = min($rleft, $x);
$break = true; break;
}
if($break) break;
}
// scanning from right to left, breaking when a pixel is found
for($x=($w4-1); $x>$rleft; $x--){
for($y=0; $y<$h4; $y++)
if(imagecolorat($img,$x,$y)){
$rright = max($rright, $x); $rbottom = max($rbottom, $y);
$break = true; break;
}
if($break) break;
}
//... //
it may be even better to check if the picture is portrait or landscape, to start the loops from
left-right(landscape) or top-bottom (portrait)
----
Server IP: 72.52.91.14
Probable Submitter: 82.227.6.122
----
Manual Page -- http://php.net/manual/en/function.imagettfbbox.php
Edit -- https://master.php.net/note/edit/118677
Del: integrated -- https://master.php.net/note/delete/118677/integrated
Del: useless -- https://master.php.net/note/delete/118677/useless
Del: bad code -- https://master.php.net/note/delete/118677/bad+code
Del: spam -- https://master.php.net/note/delete/118677/spam
Del: non-english -- https://master.php.net/note/delete/118677/non-english
Del: in docs -- https://master.php.net/note/delete/118677/in+docs
Del: other reasons-- https://master.php.net/note/delete/118677
Reject -- https://master.php.net/note/reject/118677
Search -- https://master.php.net/manage/user-notes.php