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/; |
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 |
|
|