--- trunk/lib/Frey/IconBrowser.pm 2008/11/27 15:45:00 553
+++ trunk/lib/Frey/IconBrowser.pm 2008/11/27 17:39:00 555
@@ -3,8 +3,9 @@
extends 'Frey';
with 'Frey::Web';
-with 'Frey::Path';
-with 'Frey::Storage';
+with 'Frey::Web::CombineImages';
+
+use Data::Dump qw/dump/;
has path => (
is => 'rw',
@@ -13,78 +14,6 @@
default => 'static/icons/fugue/',
);
-use GD;
-use Digest::MD5 qw/md5_hex/;
-use File::Slurp;
-use Data::Dump qw/dump/;
-
-=head2 combine_image
-
-Combine images into CSS sprites
-
- my ( $combined_path, $styles ) = $self->combine_image( @paths );
-
-=cut
-
-sub combine_image {
- my $self = shift;
- my @images = @_;
-
- my $path = 'var/combine/' . md5_hex( join(' ',@images ) );
- my $style_path = $path . '.yaml';
- $path .= '.png';
-
- return ( $path, $self->load( $style_path ) ) if -e $path;
-
- warn "# path $path";
- $self->mkbasepath( $path );
-
- # fixed dimensions of images combined
- my ( $w, $h ) = ( 16, 16 );
- my $num_images = $#images + 1;
-
- my $combined = GD::Image->new( $w, $num_images * $h )
- || die "can't create $w x ",$num_images * $h," combined image";
- $combined->trueColor( 1 );
- $combined->saveAlpha( 1 );
- my $white = $combined->colorAllocate(255,255,255);
- $combined->transparent($white);
-
- my $y = 0;
-
- my $style;
-
- foreach my $image_path ( @images ) {
- my $i = GD::Image->new( $image_path ) || die "can't open $image_path: $!";
- $i->trueColor( 1 );
- $i->saveAlpha( 1 );
-# $i->transparent($white);
-
- die "with not $w" unless $i->width == $w;
- die "with not $h" unless $i->height == $h;
-
- warn "# copy $image_path 0 x $y";
- $combined->copy( $i, 0, $y, 0, 0, $w, $h );
-
- $style->{$image_path}
- = qq|background:url(/$path) no-repeat; padding:0 0 0 | . ( $h - 1 ) . qq|px; background-position:0 |
- . ( $y ? -$y . 'px' : 0 )
- ;
-
- $y += $h;
- }
-
- write_file( $path, $combined->png );
- $self->store( $style_path, $style );
- warn
- "# combined $num_images into ",
- $combined->width, "x", $combined->height, " pixels ",
- $path, " ", -s $path , " bytes ",
- " style $style_path ", -s $style_path, " bytes";
-
- return ( $path, $style );
-}
-
sub as_markup {
my ($self) = @_;
@@ -94,7 +23,7 @@
my @icons = sort grep { m/$extension/ } readdir($dir);
closedir $dir;
- my ( $combined_path, $styles ) = $self->combine_image( map { $self->path . '/' . $_ } @icons );
+ my ( $combined_path, $styles ) = $self->combine_images( map { $self->path . '/' . $_ } @icons );
my $html;
my $base;
@@ -104,7 +33,7 @@
$name =~ s{$extension}{};
$base ||= $name; # seed with first
- my $desc;
+ my $desc = '';
my $bl = length $base;
@@ -124,8 +53,8 @@
my $path = $self->path . '/' . $icon;
- my $style = $styles->{$path} || die "can't find style for $path in ",dump( $styles );
- $html .= qq| $name$desc\n|;
+ my $pic = $styles->{$path} || die "can't find pic for $path in ",dump( $styles );
+ $html .= qq|$pic $name$desc\n|;
}