App-PNGCrush

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

{
   "abstract" : "Perl wrapper around ``pngcrush'' program",
   "author" : [
      "Zoffix Znet <zoffix@cpan.org>"
   ],
   "dynamic_config" : 1,
   "generated_by" : "Module::Build version 0.4007, CPAN::Meta::Converter version 2.132830",
   "license" : [
      "perl_5"
   ],
   "meta-spec" : {
      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",

META.yml  view on Meta::CPAN

---
abstract: "Perl wrapper around ``pngcrush'' program"
author:
  - 'Zoffix Znet <zoffix@cpan.org>'
build_requires:
  Test::More: 0
configure_requires:
  Module::Build: 0
dynamic_config: 1
generated_by: 'Module::Build version 0.4007, CPAN::Meta::Converter version 2.132830'
license: perl
meta-spec:

README  view on Meta::CPAN

App-PNGCrush

The module is a simple wrapper around ``pngcrush'' program. The program
is free open source and you can obtain it from
L<http://pmt.sourceforge.net/pngcrush/> on Debian systems you
can find it in the repos: C<sudo -H apt-get install pngcrush>

I needed this module to utilize only little subsection of C<pngcrush>'s
functionality, if you would like some features added, I am more than open
for suggestions.

INSTALLATION

To install this module, run the following commands:

	perl Build.PL
	./Build
	./Build test

lib/App/PNGCrush.pm  view on Meta::CPAN


    $self->$_(undef) for qw(error results);

    my @options = exists $args{opts}
                ? @{ $args{opts} }
                : $self->_make_options;

    my $proc = $self->proc;
    my %out;
    @out{ qw(stdout stderr status msg) }
    = $proc->run( [ 'pngcrush', @options, $in ] );

    return $self->_set_error("Proc::Reliable error: $out{error}")
        if defined $out{error};

    return $self->_set_error("File $in does not seem to exist")
        if $out{stdout} =~ /Could not find file: \Q$in/;

    @out{ qw(idat size) } = $out{stdout}
    =~ /\(([\d.]+)% IDAT reduction\).+?\(([\d.]+)% filesize reduction\)/s;

lib/App/PNGCrush.pm  view on Meta::CPAN

    return;
}

1;
__END__

=encoding utf8

=head1 NAME

App::PNGCrush - Perl wrapper around ``pngcrush'' program

=head1 SYNOPSIS

    use strict;
    use warnings;

    use App::PNGCrush;

    my $crush = App::PNGCrush->new;

    # let's use best compression and remove a few chunks
    $crush->set_options(
        qw( -d OUT_DIR -brute 1 ),
        remove  => [ qw( gAMA cHRM sRGB iCCP ) ],
    );

    my $out_ref = $crush->run('picture.png')
        or die "Error: " . $crush->error;

    print "Size reduction: $out_ref->{size}%\n"
                . "IDAT reduction: $out->{idat}%\n";

=head1 DESCRIPTION

The module is a simple wrapper around ``pngcrush'' program. The program
is free open source and you can obtain it from
L<http://pmt.sourceforge.net/pngcrush/> on Debian systems you
can find it in the repos: C<sudo -H apt-get install pngcrush>

I needed this module to utilize only little subsection of C<pngcrush>'s
functionality, if you would like some features added, I am more than open
for suggestions.

=head1 CONSTRUCTOR

=head2 C<new>

    my $crush = App::PNGCrush->new;

    my $crush = App::PNGCrush->new( max_time => 300 );

Creates a new App::PNGCrush object. Arguments are optional and passed
as key/value pairs with keys being L<Proc::Reliable> methods and values
being the values for those methods, here you can set some options
controlling how C<pngcrush> will be run. Generally, you'd worry only
about C<max_time> (which B<defaults> to C<300> seconds in C<App::PNGCrush>)
and set it to a higher value if you are about to process large images
with brute force.

=head1 METHODS

=head2 C<run>

    my $results_ref = $crush->run('pic.png')
        or die $crush->error;

    my $results_ref = $crush->run('pic.png', opts => [ qw(custom stuff) ] );

Instructs the object to run C<pngcrush>. The first argument is mandatory
and must be a filename which will be passed to C<pngcrush> as input file.
Takes one optional argument (so far), which is passed as key/value
pair; the key being C<opts> and value being an arrayref of custom options
you want to give to C<pngcrush> (those will bypass shell processing).
Generally the custom options option is in here "just in case" and B<you
are recommended to set options via individual methods or C<set_options()>
method (see below).>

Returns either C<undef> or an empty list (depending on the context)
if an error occurred and the reason for the error will be available via
C<error()> method. On success returns a hashref with the following
keys/values:

    $VAR1 = {
        'total_idat_length' => '1880',
        'cpu' => {
                    'decoding' => '0.010',
                    'other' => '0.050',
                    'total' => '0.210',
                    'encoding' => '0.150'
        },
        'stderr' => '',
        'status' => '0',
        'idat' => '0.80',
        'stdout' => '| pngcrush 1.6.4 .. blah blah full STDOUT here',
        'size' => '1.56'
    };

=head3 C<size>

    { 'size' => '1.56', }

The C<size> key will contain percentage of filesize reduction.

=head3 C<idat>

lib/App/PNGCrush.pm  view on Meta::CPAN


The C<cpu> key will contain a hashref with with four keys:
C<total>, C<decoding>, C<other> and C<encoding> with values being
number of seconds it took to process.

=head3 C<stderr>

    { 'stderr' => '', }

The C<stderr> key will contain any collected data from STDERR while
C<pngcrush> was running.

=head3 C<stdout>

    { 'stdout' => '| pngcrush 1.6.4 .. blah blah full STDOUT here', }

The C<stdout> key will contain any collected data from STDOUT while
C<pngcrush> was running.

=head3 C<status>

    { 'status' => '0' }

The C<status> key will contain the exit code of C<pngcrush>.

=head2 C<error>

    my $ret_ref = $crush->run('some.png')
        or die $crush->error;

If C<run> failed it will return either C<undef> or an empty list depending
on the context and the reason for failure will be available via C<error()>
method. Takes no arguments, returns a human parsable error message
explaining why C<run> failed.

=head2 C<results>

    my $results_ref = $crush->results;

lib/App/PNGCrush.pm  view on Meta::CPAN

returns the exact same hashref last call to C<run()> returned.

=head2 C<set_options>

    $crush->set_options(
        qw( -d OUT_DIR -brute 1 ),
        remove  => [ qw( gAMA cHRM sRGB iCCP ) ],
    );

Always returns a true value. Sets the options with which to run
C<pngcrush>. As argument takes a list of key/value pairs of
either standard C<pngcrush> options or more verbose names this module
offers (see below). If you want to B<repeat> certain option pass values
as B<an arrayref>, thus if on a command line you'd write
C<< pngcrush -rem gAMA -rem cHRM -rem sRGB ... >> you'd use
C<< ->set_options( '-rem' => [ qw( gAMA cHRM sRGB iCPP ) ] ) >>.

B<Note:> if C<pngcrush> option does not take an argument you B<must>
give it a value of C<1> when setting it via C<set_options()> method.
For C<-v> option you can set it to value C<2> to repeat twice
(aka uber verbose). B<Same applies> to individual option setting methods.

B<Note 2:> call to C<set_options()> will call C<reset_options()> method
(see below) before setting any of your options, thus whatever you
don't specify will not be passed to C<pngcrush>

=head2 C<reset_options>

    $crush->reset_options;

Always returns a true value, takes no arguments. Instructs the object
to reset all C<pngcrush> options.

=head2 individual option methods

Module provides methods to set (almost) all C<pngcrush> options individually
You'd probably would want to use C<set_options()> method (see above)
in most cases. See C<set_options()> method which describes how to
repeat options and how to set options which take no arguments in
C<pngcrush>. The following is the list of methods (on the left) and
corresponding C<pngcrush> options they set (on the right); some
options were deemed useless to the module and were not included
(this is as of C<pngcrush> version 1.6.4):

    already_size            -already
    bit_depth               -bit_depth
    background              -bkgd
    brute_force             -brute
    color_type              -c
    color_counting          -cc
    output_dir              -d
    double_image_gamma      -dou
    output_extension        -e

lib/App/PNGCrush.pm  view on Meta::CPAN

    save_unknown            -save
    srgb                    -srgb
    text                    -text
    transparency            -trns
    window_size             -w
    strategy                -z
    insert_ztxt             -zitxt
    ztxt                    -ztxt
    verbose                 -v

See C<pngcrush> manpage (C<man pngcrush> or C<pngcrush -v>)
for descriptions of these options.

Out of those listed above the following C<pngcrush> options do not take
arguments,
thus to set these you'd need to pass C<1> as an argument to the option
setting method (except for C<verbose> which can take a value of C<2> to
indicate double verboseness (equivalent to passing C<-v -v> to
C<pngcrush>)

    brute_force
    color_counting
    double_image_gamma
    fix_fatal
    output_force
    no_output
    no_color_counting
    save_unknown
    verbose

lib/App/PNGCrush.pm  view on Meta::CPAN

it must be a C<Proc::Reliable> object which will replace the currently
used one (and you just SOO don't wanna do this, do you?)

=head1 AUTHOR

Zoffix Znet, C<< <zoffix at cpan.org> >>
(L<http://zoffix.com>, L<http://haslayout.net>)

=head1 BUGS

Please report any bugs or feature requests to C<bug-app-pngcrush at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-PNGCrush>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc App::PNGCrush

You can also look for information at:



( run in 2.845 seconds using v1.01-cache-2.11-cpan-df04353d9ac )