Grayscale image: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) m (→{{header|Perl 6}}: fixed file read) |
SqrtNegInf (talk | contribs) m (Undo revision 237787 by SqrtNegInf (talk)) |
||
Line 1,115:
end</lang>
=={{header|Perl
{{libheader|Imlib2}}
Since we are using Imlib2, this one '''does''' '''not''' implement really a gray-scale (single channel) storage; it only ''converts'' an RGB image to an RGB image with the same three colour components for each pixel (which result in a gray-scale-like image)
<lang perl>#! /usr/bin/perl
use strict;
use Image::Imlib2;
sub tograyscale
{
my $gs = $r * 0.2126 + $g * 0.7152 + $b * 0.0722;▼
my
my $gimg = Image::Imlib2->new($img->width, $img->height);
for ( my $x = 0; $x < $gimg->width; $x++ ) {
for ( my $y = 0; $y < $gimg->height; $y++ ) {
my ( $r, $g, $b, $a ) = $img->query_pixel($x, $y);
# discard alpha info...
$gimg->set_color($gray, $gray, $gray, 255);
$gimg->draw_point($x, $y);
}
}
return $gimg;
}
my $animage = Image::Imlib2->load("Lenna100.jpg");
my $gscale = tograyscale($animage);
$gscale->set_quality(80);
}</lang>▼
$gscale->save("Lennagray.jpg");
=={{header|Perl 6}}==
This script expects to be fed a P6 .ppm file name at the command line. It will convert it to grey scale and save it as a binary portable grey map (P5 .pgm) file.
|