diff options
-rw-r--r-- | data/config_example.pl | 4 | ||||
-rw-r--r-- | data/global.pl | 7 | ||||
-rwxr-xr-x | util/spritegen.pl | 19 |
3 files changed, 24 insertions, 6 deletions
diff --git a/data/config_example.pl b/data/config_example.pl index 9c255bb2..b1e405ce 100644 --- a/data/config_example.pl +++ b/data/config_example.pl @@ -40,3 +40,7 @@ package VNDB; # Uncomment the compression method to use for the generated Javascript (or just leave as-is to disable compression) #$JSGEN{compress} = 'JavaScript::Minifier::XS'; #$JSGEN{compress} = "|/usr/bin/uglifyjs --compress --mangle"; + +# Uncomment to generate an extra small icons.png (note: setting both pngcrush and slow options really is slow) +#$SPRITEGEN{pngcrush} = '/usr/bin/pngcrush'; +#$SPRITEGEN{slow} = 1; diff --git a/data/global.pl b/data/global.pl index 5cefa5ff..de810926 100644 --- a/data/global.pl +++ b/data/global.pl @@ -140,6 +140,13 @@ our %JSGEN = ( ); +# Options for spritegen.pl +our %SPRITEGEN = ( + slow => 0, + pngcrush => undef, +); + + # allow the settings to be overwritten in config.pl require $ROOT.'/data/config.pl' if -f $ROOT.'/data/config.pl'; diff --git a/util/spritegen.pl b/util/spritegen.pl index c6f830f7..3b3c88c3 100755 --- a/util/spritegen.pl +++ b/util/spritegen.pl @@ -1,5 +1,7 @@ #!/usr/bin/perl +package VNDB; + use strict; use warnings; use Image::Magick; @@ -7,9 +9,11 @@ use Cwd 'abs_path'; our $ROOT; BEGIN { ($ROOT = abs_path $0) =~ s{/util/spritegen\.pl$}{}; } +require $ROOT.'/data/global.pl'; my $path = "$ROOT/data/icons"; my $icons = "$ROOT/static/f/icons.png"; +my $ticons = "$ROOT/static/f/icons~.png"; my $css = "$ROOT/data/icons/icons.css"; my @img = map { @@ -78,8 +82,8 @@ sub minstrip { my $optsize = 1e10; for my $w ($minwidth..$maxwidth) { my $size = genstrip($w)*$w; - # To optimize for file size, uncommment below line. It's slow, but saves about 150 bytes (while using pngcrush). - #$size = img(); + # Optimize for file size rather than pixel count if slow is set + $size = img() if $VNDB::SPRITEGEN{slow}; if($size < $optsize) { $optw = $w; $optsize = $size; @@ -108,12 +112,15 @@ sub img { for my $i (@img) { print $img->Composite(image => $i->{i}, x => $i->{x}, y => $i->{y}); } - print $img->Write($icons); + print $img->Write("png32:$ticons"); undef $img; - `pngcrush -q "$icons" "$icons~" 2>/dev/null && mv "$icons~" "$icons"`; + if($VNDB::SPRITEGEN{pngcrush}) { + `$VNDB::SPRITEGEN{pngcrush} -q "$ticons" "$ticons~"`; + rename "$ticons~", $ticons or die $!; + } - my $size = -s $icons; + my $size = -s $ticons; #printf "Dim: %dx%d, size: %d, pixels wasted: %d\n", $w, $h, $size, $w*$h-$minpixels; $size; } @@ -137,7 +144,7 @@ sub css { } -#genstrip 80; minstrip; img; css; +rename $ticons, $icons or die $!; |