CSS-SpriteMaker

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

      },
      "configure" : {
         "requires" : {
            "ExtUtils::MakeMaker" : "0"
         }
      },
      "runtime" : {
         "requires" : {
            "File::Find" : "0",
            "Getopt::Long" : "0",
            "Image::Magick" : "0",
            "Module::Pluggable" : "0",
            "perl" : "5.006"
         }
      },
      "test" : {
         "requires" : {
            "File::Find" : "0",
            "Getopt::Long" : "0",
            "Image::Magick" : "0",
            "Module::Pluggable" : "0",
            "Test::More" : "0"
         }
      }
   },
   "release_status" : "stable",
   "resources" : {
      "repository" : {
         "type" : "git",
         "web" : "https://github.com/lokku/Css-SpriteMaker"

META.yml  view on Meta::CPAN

---
abstract: 'Combine several images into a single CSS sprite'
author:
  - 'Savio Dimatteo <darksmo@gmail.com>'
build_requires:
  ExtUtils::MakeMaker: '0'
  File::Find: '0'
  Getopt::Long: '0'
  Image::Magick: '0'
  Module::Pluggable: '0'
  Test::More: '0'
configure_requires:
  ExtUtils::MakeMaker: '0'
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 7.0401, CPAN::Meta::Converter version 2.150005'
license: perl
meta-spec:
  url: http://module-build.sourceforge.net/META-spec-v1.4.html
  version: '1.4'
name: CSS-SpriteMaker
no_index:
  directory:
    - t
    - inc
requires:
  File::Find: '0'
  Getopt::Long: '0'
  Image::Magick: '0'
  Module::Pluggable: '0'
  perl: '5.006'
resources:
  repository: https://github.com/lokku/Css-SpriteMaker
version: '1.01'
x_serialization_backend: 'CPAN::Meta::YAML version 0.012'

Makefile.PL  view on Meta::CPAN

require 5.006;
use strict;
use warnings;
use ExtUtils::MakeMaker;

my %prereqs = (
    'File::Find'     => 0,
    'Getopt::Long'   => 0,
    'Image::Magick'  => 0,
    'Module::Pluggable' => 0,
);

WriteMakefile(
    NAME => 'CSS::SpriteMaker',
    LICENSE => 'perl',
    AUTHOR => q{Savio Dimatteo <darksmo@gmail.com>},
    VERSION_FROM => 'lib/CSS/SpriteMaker.pm',
    ABSTRACT_FROM => 'lib/CSS/SpriteMaker.pm',
    TEST_REQUIRES => {

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

package CSS::SpriteMaker;

use strict;
use warnings;

use File::Find;
use Image::Magick;
use List::Util qw(max);

use Module::Pluggable 
    search_path => ['CSS::SpriteMaker::Layout'],
    except => qr/CSS::SpriteMaker::Layout::Utils::.*/,
    require => 1,
    inner => 0;

use POSIX qw(ceil);

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

        # layout_name is used as default
        layout => {
            name => $opts{layout_name},
            # no options by default
            options => {}
        },
        rc_filename_to_classname => $opts{rc_filename_to_classname},
        rc_override_classname => $opts{rc_override_classname},

        # the maximum color value
        color_max => 2 ** Image::Magick->QuantumDepth - 1,
    };

    return bless $self, $class;
}

=head2 compose_sprite

Compose many sprite layouts into one sprite. This is done by applying
individual layout separately, then merging the final result together using a
glue layout.

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

        die "The 'layout' parameter needs to be specified for _write_image, and must be a CSS::SpriteMaker::Layout object";
    }

    $self->_verbose(" * writing sprite image");

    $self->_verbose(sprintf("Target image size: %s, %s",
        $Layout->width(),
        $Layout->height())
    );

    my $Target = Image::Magick->new();

    $Target->Set(size => sprintf("%sx%s",
        $Layout->width(),
        $Layout->height()
    ));

    # prepare the target image
    if (my $err = $Target->ReadImage('xc:white')) {
        warn $err;
    }

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

        my ($layout_x, $layout_y) = $Layout->get_item_coord($source_id);

        $self->_verbose(sprintf(" - placing %s (format: %s  size: %sx%s  position: [%s,%s])",
            $rh_source_info->{pathname},
            $rh_source_info->{format},
            $rh_source_info->{width},
            $rh_source_info->{height},
            $layout_y,
            $layout_x
        ));
        my $I = Image::Magick->new(); 
        my $err = $I->Read($rh_source_info->{pathname});
        if ($err) {
            warn $err;
            next ITEM_ID;
        }

        my $padding = $rh_source_info->{add_extra_padding};

        my $destx = $layout_x + $padding;
        my $desty = $layout_y + $padding;

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


=cut

sub _get_image_properties {
    my $self       = shift;
    my $image_path = shift;
    my $remove_source_padding = shift;
    my $add_extra_padding = shift;
    my $enable_colormap = shift;

    my $Image = Image::Magick->new();

    my $err = $Image->Read($image_path);
    if ($err) {
        warn $err;
        return {};
    }

    my $rh_info = {};
    $rh_info->{first_pixel_x} = 0,
    $rh_info->{first_pixel_y} = 0,



( run in 0.390 second using v1.01-cache-2.11-cpan-beeb90c9504 )