/[Frey]/trunk/lib/Frey/Web/CombineImages.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Frey/Web/CombineImages.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 556 by dpavlin, Thu Nov 27 17:39:00 2008 UTC revision 557 by dpavlin, Thu Nov 27 19:19:01 2008 UTC
# Line 4  use Moose::Role; Line 4  use Moose::Role;
4  with 'Frey::Path';  with 'Frey::Path';
5  with 'Frey::Storage';  with 'Frey::Storage';
6    
7  use GD;  use Imager;
8  use Digest::MD5 qw/md5_hex/;  use Digest::MD5 qw/md5_hex/;
9  use File::Slurp;  use File::Slurp;
10  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
# Line 35  sub combine_images { Line 35  sub combine_images {
35          my $padding = 5; # space between pictures when used within text          my $padding = 5; # space between pictures when used within text
36          my $num_images = $#images + 1;          my $num_images = $#images + 1;
37    
38          my $combined = GD::Image->new( $w, $num_images * $h )          my $combined = Imager->new(
39                  || die "can't create $w x ",$num_images * ($h + $padding)," combined image";                  xsize => $w,
40          $combined->trueColor( 1 );                  ysize => $num_images * ( $h + $padding ),
41          $combined->saveAlpha( 1 );                  channels => 4, # RGB+alpha
42          my $white = $combined->colorAllocate(255,255,255);          ) || die "can't create $w x ",$num_images * ($h + $padding)," combined image";
         $combined->transparent($white);  
43    
44          my $y = 0;          my $y = 0;
45    
46          my $style;          my $style;
47    
48          foreach my $image_path ( @images ) {          foreach my $image_path ( @images ) {
49                  my $i = GD::Image->new( $image_path ) || die "can't open $image_path: $!";                  my $i = Imager->new;
50                  my $i_white = $i->colorAllocate(255,255,255);                  $i->read( file => $image_path ) || die "can't open $image_path: $!";
                 $i->transparent( $i_white );  
                 $i->saveAlpha( 1 );  
                 $i->trueColor( 1 );  
51    
52                  die "with not $w" unless $i->width == $w;                  die "with not $w" unless $i->getwidth == $w;
53                  die "with not $h" unless $i->height == $h;                  die "with not $h" unless $i->getheight == $h;
54    
55                  warn "# copy $image_path 0 x $y";                  warn "# copy $image_path 0 x $y" if $self->debug;
56                  $combined->copy( $i, 0, $y, 0, 0, $w, $h );                  $combined->paste( img => $i, left => 0, top => $y );
57    
58                  $style->{$image_path}                  $style->{$image_path}
59                          = qq|<span style="|                          = qq|<span style="|
60                          . qq|background:url(/$path) no-repeat; |                          . qq|background: url(/$path) no-repeat 0px | . -$y . qq|px; |
                         . qq|background-position: 0px | . -$y . qq|px; |  
61                          . qq|padding: 0 0 0 | . ( $w + 3 ) . qq|px; |                          . qq|padding: 0 0 0 | . ( $w + 3 ) . qq|px; |
62                          . qq|width: ${w}px; height: ${h}px; |                          . qq|width: ${w}px; height: ${h}px; |
63                          . qq|"></span>|;                          . qq|"> </span>|;
64                          ;                          ;
65    
66                  $y += $h + $padding;                  $y += $h + $padding;
67          }          }
68    
69          write_file( $path, $combined->png );          $combined->write( file => $path ) || die "can't write $path: $!";
70          $self->store( $style_path, $style );          $self->store( $style_path, $style ) || die "can't store $style_path: $!";
71          warn          warn
72                  "# combined $num_images into ",                  "# combined $num_images ${w}x${h} images into ",
73                  $combined->width, "x", $combined->height, " pixels ",                  $combined->getwidth, "x", $combined->getheight, " ",
74                  $path, " ", -s $path , " bytes ",                  $path, " ", -s $path , " bytes ",
75                  " style $style_path ", -s $style_path, " bytes";                  " style $style_path ", -s $style_path, " bytes";
76    

Legend:
Removed from v.556  
changed lines
  Added in v.557

  ViewVC Help
Powered by ViewVC 1.1.26