Check if image is mostly black or white

   function needs_invert($im)
   {  $r = MagickGetImageHistogram($im);
      $black = $white = 0;
      foreach ($r as $p)
      {  $tot = PixelGetGreen($p) + PixelGetRed($p) + PixelGetBlue($p);
         if ($tot > 0)
         {  $black = PixelGetColorCount($p);
         }
         else
         {  $white = PixelGetColorCount($p);
         }
      }
      if ($black > $white)
      {  return true;
      }
      return false;
   }

Reading an image from a string (aka blob)

 
$result = MagickReadImageBlob($im, $blob);
if (!$result)   { echo MagickGetExceptionString($im);  exit;}

-- MattWalsh - 22 Jul 2007

Topic revision: r1 - 22 Jul 2007 - MattWalsh
 
This site is powered by the TWiki collaboration platformCopyright © 2008-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback