update page now

Voting

: max(five, six)?
(Example: nine)

The Note You're Voting On

gw at example dot com
10 years ago
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)

<< Back to user notes page

To Top