summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2015-08-17 16:53:43 +0200
committerYorhel <git@yorhel.nl>2015-08-17 17:00:45 +0200
commit5c9b8d37e72792344266fecf5d6336f3e483f677 (patch)
tree9f193dcd064b80a303eec761e768735663f43229 /util
parent6f424c8a6765c00c5df7b359ab4c8d409c758738 (diff)
spritegen.pl: Add pngcrush/slow options + force png32 + atomic replace
A recent version of imagemagick creates 16 bit depth PNG images by default for some reason. This results in an unnecessarily large file size increase and pngcrush doesn't do much to counter it (and its -bit_depth option has been deprecated, too). The atomic replace is quite handy to avoid people seeing any wierd intermediate images while the slow+pngcrush options are being used.
Diffstat (limited to 'util')
-rwxr-xr-xutil/spritegen.pl19
1 files changed, 13 insertions, 6 deletions
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 $!;