Name

pixel — color of a pixel

Synopsis

$image->Set('pixel[x,y]'=>color);
$image->Get('pixel[x,y]')

The pixel attribute returns the red, green, blue, and opacity value (or colormap index for colormapped images) at the given coordinate as four decimal numbers separated by commas. For example, if an image has a white pixel at 20, 50:

@pixel = split /,/, $image->Get('pixel[20,50]');
print "Red: $pixel[0]\n",
      "Green: $pixel[1]\n",
      "Blue: $pixel[2]\n",
      "Opacity: $pixel[3]\n";

will print the following:

Red: 255
Green: 255
Blue: 255
Opacity: 0

If you want to change a group of pixels, use the Draw( ) method with the color primitive.

Get Programming Web Graphics with Perl and GNU Softwar now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.