CSS-SpriteBuilder

 view release on metacpan or  search on metacpan

lib/CSS/SpriteBuilder.pm  view on Meta::CPAN

    }

    my %global_opts = (
        ( map { $_             => $self->{$_}       } grep { exists $self->{$_} } @{ SPRITE_OPTS() } ),
        ( map { $_->nodeName() => $_->textContent() } $dom->findnodes("/root/global_opts/*")        ),
    );

    my @sprites;
    foreach my $sprite_node ( $dom->findnodes("/root/sprites/sprite") ) {
        my %sprite_opts = (
            %global_opts,
            map { $_->nodeName() => $_->textContent() } $sprite_node->findnodes("@*"),
        );

        my @images = map +{
            ( map { $_             => $sprite_opts{$_}  } grep { exists $sprite_opts{$_} } @{ IMAGE_OPTS() }   ),
            ( map { $_->nodeName() => $_->textContent() } $_->findnodes("@*")                                  ),
        }, $sprite_node->findnodes('image');

        push @sprites, {
            %sprite_opts,
            images => \@images,
        };
    }

    return wantarray ? @sprites : \@sprites;
}

1;
__END__

=head1 NAME

CSS::SpriteBuilder - CSS sprite builder.

=head1 SYNOPSIS

    use CSS::SpriteBuilder

    my $builder = CSS::SpriteBuilder->new( [%args] );
    $builder->build(
        sprites => [{
            file   => 'sample_sprite_%d.png',
            images => [
                { file => 'small/Add.png', [ %options ] },
            ],
            [ %options ],
        }],
    );

    $build->write_css('sprite.css');

    Or

    $builder->build(config => 'config.xml');

    $build->write_css('sprite.css');

=head1 DESCRIPTION

This module generate CSS sprites with one of these modules: Image::Magick or GD.

It has many useful settings and can be used for sites with complex structure.

=head1 METHODS

=head2 new(<%args>)

my $builder = CSS::SpriteBuilder->new(<%args>);

Create instance.

Valid arguments are:

=over

=item * B<source_dir> [ = undef ]

Specify custom location for source images.

=item * B<output_dir> [ = undef ]

Specify custom location for generated images.

=item * B<image_quality> 0..100 [ = 90 ]

Specify image quality for generated images (for JPEG only).

=item * B<max_image_size> [ = 65536 ]

Specify max size of images that will be used to generate a sprite.

=item * B<max_image_width> [ = 2000 ]

Specify max width of images that will be used to generate a sprite.

=item * B<max_image_height> [ = 2000 ]

Specify max height of images that will be used to generate a sprite.

=item * B<max_sprite_width> [ = 2000 ]

Specify max width of sprite.
When sprite has no free space, than creates a new sprite with addition of a suffix to the sprite name.
Opera 9.0 and below have a bug which affects CSS background offsets less than -2042px. All values less than this are treated as -2042px exactly.

=item * B<max_sprite_height> [ = 2000 ]

Specify max height of sprite.

=item * B<margin> [ = 0 ]

Add margin to each image.

=item * B<transparent_color> [ = undef ]

Set transparent color for image, for example: 'white', 'black', ....

=item * B<is_background> [ = 0 ]

If B<is_background> flag is '0' will be generated CSS rule such as: 'width:XXXpx;height:YYYpx;'.



( run in 1.618 second using v1.01-cache-2.11-cpan-39bf76dae61 )