summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/config_example.pl9
-rw-r--r--data/global.pl8
-rwxr-xr-xutil/jsgen.pl2
-rwxr-xr-xutil/skingen.pl8
-rwxr-xr-xutil/spritegen.pl37
5 files changed, 39 insertions, 25 deletions
diff --git a/data/config_example.pl b/data/config_example.pl
index 96f003fc..ce272637 100644
--- a/data/config_example.pl
+++ b/data/config_example.pl
@@ -40,6 +40,11 @@ package VNDB;
#$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';
+# Uncomment to create pre-compressed css and js files using zopfli
+#$JSGEN{gzip} = $SKINGEN{gzip} = "/usr/bin/zopfli";
+
+# Uncomment to generate an extra small icons.png
+# (note: using zopflipng or pngcrush with the slow option is *really* slow, but compresses awesomely)
+#$SPRITEGEN{crush} = '/usr/bin/pngcrush -q';
+#$SPRITEGEN{crush} = '/usr/bin/zopflipng -m --lossy_transparent';
#$SPRITEGEN{slow} = 1;
diff --git a/data/global.pl b/data/global.pl
index 29f1a6c9..ca1df4d3 100644
--- a/data/global.pl
+++ b/data/global.pl
@@ -137,13 +137,19 @@ our %M = (
# Options for jsgen.pl
our %JSGEN = (
compress => undef,
+ gzip => undef,
);
# Options for spritegen.pl
our %SPRITEGEN = (
slow => 0,
- pngcrush => undef,
+ crush => undef,
+);
+
+# Options for skingen.pl
+our %SKINGEN = (
+ gzip => undef,
);
diff --git a/util/jsgen.pl b/util/jsgen.pl
index 72c78d9f..c677d791 100755
--- a/util/jsgen.pl
+++ b/util/jsgen.pl
@@ -183,6 +183,8 @@ sub save {
}
rename "$f~", $f or die $!;
+
+ `$VNDB::JSGEN{gzip} -c '$f' >'$f.gz'` if $VNDB::JSGEN{gzip};
}
sub jsgen {
diff --git a/util/skingen.pl b/util/skingen.pl
index 834578cb..aa5db2d5 100755
--- a/util/skingen.pl
+++ b/util/skingen.pl
@@ -72,9 +72,15 @@ sub writeskin { # $name
my $css = join '', <$CSS>;
close $CSS;
$css =~ s/\$$_\$/$o{$_}/g for (keys %o);
- open my $SKIN, '>', "$ROOT/static/s/$name/style.css" or die $!;
+
+ my $f = "$ROOT/static/s/$name/style.css";
+ open my $SKIN, '>', "$f~" or die $!;
print $SKIN $CSS::Minifier::XS::VERSION ? CSS::Minifier::XS::minify($css) : $css;
close $SKIN;
+
+ rename "$f~", $f;
+
+ `$VNDB::SKINGEN{gzip} -c '$f' >'$f.gz'` if $VNDB::SKINGEN{gzip};
}
diff --git a/util/spritegen.pl b/util/spritegen.pl
index 3b3c88c3..e8b60017 100755
--- a/util/spritegen.pl
+++ b/util/spritegen.pl
@@ -60,7 +60,11 @@ sub genstrip {
$i->{y} = $h;
$h += $i->{h};
}
- return $h;
+
+ # Recalculate the (actually used) width
+ $w = 0;
+ $w < $_->{x}+$_->{w} && ($w = $_->{x}+$_->{w}) for (@img);
+ ($w, $h);
}
@@ -78,33 +82,25 @@ sub minstrip {
$minwidth = $_->{w} if $_->{w} > $minwidth;
$maxwidth += $_->{w};
}
- my $optw;
- my $optsize = 1e10;
- for my $w ($minwidth..$maxwidth) {
- my $size = genstrip($w)*$w;
+
+ my($optsize, $w, $h, $optw, $opth) = (1e9, $maxwidth);
+ while($w >= $minwidth) {
+ ($w, $h) = genstrip($w);
# Optimize for file size rather than pixel count if slow is set
- $size = img() if $VNDB::SPRITEGEN{slow};
+ my $size = $VNDB::SPRITEGEN{slow} ? img($w, $h) : $w*$h;
if($size < $optsize) {
$optw = $w;
+ $opth = $h;
$optsize = $size;
}
+ $w--;
}
genstrip($optw);
}
-sub calcdim {
- my($w, $h) = (0,0);
- for (@img) {
- $w = $_->{x}+$_->{w} if $w < $_->{x}+$_->{w};
- $h = $_->{y}+$_->{h} if $h < $_->{y}+$_->{h};
- }
- ($w, $h)
-}
-
-
sub img {
- my($w, $h) = calcdim;
+ my($w, $h) = @_;
my $img = Image::Magick->new;
print $img->Set(size => "${w}x$h");
print $img->ReadImage('canvas:rgba(0,0,0,0)');
@@ -115,8 +111,8 @@ sub img {
print $img->Write("png32:$ticons");
undef $img;
- if($VNDB::SPRITEGEN{pngcrush}) {
- `$VNDB::SPRITEGEN{pngcrush} -q "$ticons" "$ticons~"`;
+ if($VNDB::SPRITEGEN{crush}) {
+ `$VNDB::SPRITEGEN{crush} "$ticons" "$ticons~"`;
rename "$ticons~", $ticons or die $!;
}
@@ -144,7 +140,6 @@ sub css {
}
-minstrip;
-img;
+img minstrip;
css;
rename $ticons, $icons or die $!;