|
Posted by Jerry Stuckle on 04/16/07 19:21
comp.lang.php wrote:
<snip>
> Thank you, Jerry, very nice to hear this! Unfortunately no I never
> did solve the problem; I am still not capable of grayscaling an image:
>
> /**
> * Make the image grayscale
> *
> * @access protected
> */
> function makeGray() { // VOID METHOD
> global $section;
> for ($i = 0; $i <= 255; $i++) $colorNDX[$i] =
> @imagecolorallocate($this->$section, $i, $i, $i);
>
> for ($y = 0; $y < $this->{$section . '_height'}; $y++) {
> for ($x = 0; $x < $this->{$section . '_width'}; $x++) {
> $ndx = @imagecolorat($this->$section, $x, $y);
> $red = ($ndx >> 16) & 0xFF;
> $green = ($ndx >> 8) & 0xFF;
> $blue = $ndx & 0xFF;
> //$ndxColorArray = @imagecolorsforindex($this->$section, $ndx);
> //$avg = floor(($ndxColorArray['red'] + $ndxColorArray['green'] +
> $ndxColorArray['blue']) / 3);
> $col = $red * 0.299 + $green * 0.587 + $blue * 0.114;
> @imagesetpixel($this->$section, $x, $y, $colorNDX[$col]);
> }
> }
>
>
>
> //@imagecopy($this->newImage, $this->$section, 0, 0, 0, 0,
> // $this->{$section . '_width'}, $this->{$section .
> '_height'});
>
> }
>
> No image is ever produced in spite of the code produced.
>
>> For your next post try alt.anal.orifices. It matches you perfectly.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
>
I'm sorry, I thought you found a fix for it.
I looked at the code, but unfortunately I'm that great with the image
functions.
A couple of things I do see. First of all, you shouldn't use a global
($section). Anything you need you should pass to the function or the
class itself.
Also, in your constructor you're saving things in $this->$val, which is
incorrect in two counts. It should be $this->val, and you never defined
$val in your class. No idea what the code would do in this case.
And I'm not sure just what you're trying to accomplish in the foreach()
loop in your constructor. If you're trying to use this to create
variables in your class, that's the hard way to go about it, and the
values you're defining are temporary and will disappear at the end of
the function. Rather, you should just define them as members of the
class (probably private).
Also, I'm not sure what's in $section, but I think you're trying to get
the width and height of the image.
As for your makeGray() function -
You should first define $colorNDX as an array, i.e.
$colorNDX = array();
Your if statement following the for loop is unnecessary - you already
know it's an array of 256 elements because you just created it. And the
following nested for statements are referencing variables which don't
exist any more.
These are just off the top of my head, and may not be correct. But I
did find our class to be pretty hard to understand.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|