I'm sorry but that too breaks. Perhaps a code review is in order, I realize that imageColorsTotal($this->image) produces 0, which I am afraid I don't understand:
class ImageGrayscaleGenerator {
/*---------------------------------------------------------------------------------------------------------------------------------------------------------
This class exists due to the rather poor performance of the imagecopymergegray() command
Borrowing code snippet from [url]http://us3.php.net/manual/en/function.imagecopymergegray.php[/url] first line comment
Will perform actual grayscaling of image one pixel at a time.
-----------------------------------------------------------------------------------------------------------------------------------------------------------*/
var $image, $image_width, $image_height;
// REMEMBER TO USE REFERENCE POINTER ONTO $image OBJECT TO ENSURE "static" CHANGE TO OBJECT AND NOT TO INSTANCE
function ImageGrayscaleGenerator(&$image) { // CONSTRUCTOR
$this->image =& $image;
}
function makeGray() { // VOID METHOD
print_r($this->image); print_r("<P>");
print_r(@imageColorsTotal($this->image) . "<P>");
for ($i = 0; $i < @imagecolorstotal($this->image); $i++) {
$colorArray = @imageColorsForIndex($this->image, $i);
print_r($colorArray); print_r("<P>");
$avg = floor(($colorArray['red'] + $colorArray['green'] + $colorArray['blue']) / 3);
@imageColorSet($this->image, $i, $avg, $avg, $avg);
}
}
}
Thanx
Phil
"CountScubula" wrote in message news:<_rSTb.19724$up5.18401@newssvr27.news.prodigy.com>...
Try running an average of the three colors:
$avg = floor( ( $color['red']) + $color['green']) + $color['blue']) ) / 3 )
$R= $avg; $B = $avg; $G = $avg;
imageColorSet($image_id, $a, $R, $G, $😎;
--
Mike Bradley
http://www.gzentools.com -- free online php tools
"Phil Powell" <> wrote in message
news:1cdca2a7.0402030910.a9109fc@posting.google.com...
I borrowed this code from a source:
for($a=0;$a<imagecolorstotal ($image_id);$a++)
{
$color = imageColorsForIndex($image_id,$i);
$R=.299 ($color['red'])+ .587 ($color['green'])+ .114
($color['blue']);
$G=.299 ($color['red'])+ .587 ($color['green'])+ .114
($color['blue']);
$B=.299 ($color['red'])+ .587 ($color['green'])+ .114 *
($color['blue']);
imageColorSet($image_id, $a, $R, $G, $😎;
}
using an image (in this case I'm using a JPEG) that is a true color
image I was unable to successfully use imagecopymergegray since that
washed out my hues/saturation altogether making the image illegible
(imagecopymergegray + imagecreate); otherwise, the colors overrode
imagecopymergegray (imagecopymergegray + imagecreatetruecolor).
Using the code I borrowed I was able to change the image.. except that
it turned jet black instead!
Has anyone ever successfully grayscaled an image using GD library? If
so, how did you do it?
Thanx
Phil