The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Image::PNG::Data - manipulate the image data part of PNGs

SYNOPSIS

    use Image::PNG::Data;

VERSION

This documents version 0.01 of Image-PNG-Data corresponding to git commit 64ed7dcffc6a69ab13a59d60c01a8c10fae08e53 released on Thu Apr 8 17:01:29 2021 +0900.

DESCRIPTION

This module provides various utilities for manipulating and testing the image data part of a PNG image. This is a companion module to Image::PNG::Libpng by the same authors.

The documentation below refers to functions which are not yet implemented.

FUNCTIONS

alpha_unused

    if (alpha_unused (read_png_file ('some.png')) {

Is the alpha channel in the image unused? This function returns a true value if the PNG has an alpha channel and it is not being used. If the image doesn't have an alpha channel it returns the undefined value. If it has an alpha channel and it is being used it returns 0.

any2gray8

    my $wpng = any2gray8 ("any.png");

Convert any type of PNG file whatsoever into a bit-depth 8 grayscale image without an alpha channel (PNG_COLOR_TYPE_GRAY). The return value is a write structure as made by "create_write_struct" in Image::PNG::Libpng.

Currently the tRNS chunk (see "tRNS" in Image::PNG::Libpng) is ignored by this.

By default the alpha channel is set to either the value of the bKGD chunk (see "bKGD" in Image::PNG::Libpng) if there is one, or white if not. You can set another background using the option bkgd:

    my $wpng = any2gray8 ('any.png', bkgd => {red => 255, green => 0, blue => 99});

This will of course be ignored if any.png does not contain an alpha channel. RGB to gray conversion is done using "set_rgb_to_gray" in Image::PNG::Libpng with the default values.

This function is not supported for versions of libpng earlier than 1.6.14.

bwpng

    my $png = bwpng (\@rows, sq => 20);

Convert boolean-style data into a black and white PNG. A two-color PNG is also possible:

    bwpng (\@rows, black => '#CFF', white => '#C00');

rgb2gray

    my $gray_png = rgb2gray ('colorful.png');

Convert an RGB PNG image to a grayscale one.

Options:

grayonly

rmalpha

    my $png = rmalpha ('file.png');

Remove the alpha channel of the PNG. If the input PNG has a color type other than GRAY_ALPHA or RGB_ALPHA, a warning is printed and the return value is undefined. The return value is an Image::PNG::Libpng structure for writing with the alpha channel data removed.

split_alpha

Unimplemented, due to be copied from Image::PNG::Libpng.

DEPENDENCIES

Image::PNG::Libpng

SEE ALSO

Online PNG tools

https://onlinepngtools.com/convert-png-to-grayscale

Converts your PNG to grayscale via JavaScript. This actually resizes the image to the size of its box, but you can save the image with the Save as... link and you get the original size back.

https://pinetools.com/grayscale-image

AUTHOR

Ben Bullock, <bkb@cpan.org>

COPYRIGHT & LICENCE

This package and associated files are copyright (C) 2021 Ben Bullock.

You can use, copy, modify and redistribute this package and associated files under the Perl Artistic Licence or the GNU General Public Licence.