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