Voting

: min(eight, nine)?
(Example: nine)

The Note You're Voting On

code_couturier at graffiti dot net
21 years ago
# very fast way to generate a grayscal-
# image from a true color image

#...

# --- quick grayscale image
for ($y = 0; $y <$img_height; $y++) {
for ($x = 0; $x <$img_width; $x++) {

# here we extract the green from
# the pixel at x,y , to use it as gray value
$gray = (ImageColorAt($image, $x, $y) >> 8) & 0xFF;

# a more exact way would be this:
# $rgb = ImageColorAt($image, $x, $y);
# $red = ($rgb >> 16) & 0xFF;
# $green = (trgb >> 8) & 0xFF;
# $blue = $rgb & 0xFF;
# $gray = (int)(($red+$green+$blue)/4);

# and here we set the new pixel/color
imagesetpixel ($image, $x, $y,
ImageColorAllocate ($image, $gray,$gray,$gray));
}
}

# ...

<< Back to user notes page

To Top