Download THE THIRD - tmok.com
Transcript
INDEPTH
Listing 9. Create a quick prelight image for mouse-over events.
...
sub monkeyiq_gimp_prelight {
my($inputimagename,$outfilename,
$brightness, $contrast ) = @_;
$img = gimp_file_load( $inputimagename,
$inputimagename );
print "prelight $inputimagename";
print " to $outfilename\n";
@layers = gimp_image_get_layers( $img );
foreach $l (@layers)
{
gimp_brightness_contrast( $l,
$brightness, $contrast );
}
imageOutput( $img, $outfilename );
}
...
"*",
[
[PF_STRING, "inputimage",
"Name of image to export", ""],
[PF_STRING, "outputimage",
"Name of image to save to", ""],
[PF_INT,
"brightness",
"-127 to 127", ""],
[PF_INT,
"contrast",
"-127 to 127", ""],
],
...
pixel’s old alpha values. Next, a selection is performed using the
nominated background color, and that selection is inverted. So,
the selection should contain everything in the image and effectively
be defining a single-bit alpha mask for what pixels should be fully
transparent in the image.
The next block adds another new layer to the image, $newlayer,
with a transparent color, and then it copies and pastes the selection from the above merged layer (everything other than the background color) into the new layer. We don’t need the old merged
image layer anymore, so it is set to hidden and only the new layer
is shown.
The result is that the new layer contains the old image data
that has had any partially transparent pixels merged with the
nominated background color. There is a only a single color that is
transparent, and the rest are fully opaque.
The imageOutput function is a little utility function in the
MonkeyIQGIMP module that handles saving to native GIMP xcf
files, but it also does something sane if a non-xcf file is desired.
Parts of MonkeyIQGimp are shown in Listing 3. The imageOutput
function simply dispatches to one of the gimp_*_save() functions
with the only difference being that for non-native formats, first