Jdrewniak has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/389934 )
Change subject: Add a new image optimizer for PNG fallback
......................................................................
Add a new image optimizer for PNG fallback
Adding the pngquant-bin module to optimize the PNG sprite fallback
image. Pngquant offers about a 60% savings on the PNG file size, from
30kb down to 10kb.
Bug: T129634
Change-Id: I7bf03b47d495b44a63f4d18bac9e484f15ad862a
---
M gulpfile.js
M package.json
2 files changed, 28 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/portals
refs/changes/34/389934/1
diff --git a/gulpfile.js b/gulpfile.js
index d134a4e..81e407a 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -4,6 +4,7 @@
/* globals console */
/* globals JSON */
/* globals Buffer */
+/* globals Promise */
/* eslint dot-notation: ["error", { "allowKeywords": false }] */
var gulp = require( 'gulp' ),
gulpLoadPlugins = require( 'gulp-load-plugins' ),
@@ -19,6 +20,9 @@
plugins = gulpLoadPlugins(),
gulpSlash = require( 'gulp-slash' ),
replace = require( 'gulp-replace' ),
+ execFile = require( 'child_process' ).execFile,
+ pngquant = require( 'pngquant-bin' ),
+ vinylPaths = require( 'vinyl-paths' ),
portalParam = argv.portal,
getBaseDir, getProdDir, getConfig;
@@ -452,6 +456,27 @@
.pipe( plugins.svg2png() )
.pipe( gulp.dest( getBaseDir() + 'assets/img/' ) );
} );
+
+/**
+ * Optimize PNG fallback.
+ */
+gulp.task( 'optimizePNGfallback', [ 'convertSVGtoPNG' ], function() {
+ return gulp.src( getConfig().img.sprite.outputPNGGlob )
+ .pipe(
+ vinylPaths( function ( imagePath ) {
+ return new Promise( function( resolve, reject ) {
+ return execFile( pngquant, [ imagePath, '-f',
'-ext', '.png' ], function( err ) {
+ if ( err ) {
+ return reject();
+ } else {
+ return resolve();
+ }
+ } );
+ } );
+ } )
+ );
+} );
+
/**
* Replace '.svg' with '.png' extension in the SVG sprite CSS file.
* This creates a PNG fallback for the SVG sprite in the sprite.css file.
@@ -473,7 +498,7 @@
return gulp.src( conf.img.src ).pipe( gulp.dest( conf.img.dest ) );
} );
-gulp.task( 'svgSprite', [ 'createSvgSprite', 'convertSVGtoPNG',
'replaceSVGSpriteCSS' ] );
+gulp.task( 'svgSprite', [ 'createSvgSprite', 'convertSVGtoPNG',
'optimizePNGfallback', 'replaceSVGSpriteCSS' ] );
gulp.task( 'lint', [ 'lint-js', 'lint-css' ] );
diff --git a/package.json b/package.json
index f616ecf..54ec09e 100644
--- a/package.json
+++ b/package.json
@@ -38,6 +38,7 @@
"jshint": "^2.9.2",
"moment": "^2.10.6",
"phantomjs-prebuilt": "^2.1.3",
+ "pngquant-bin": "^3.1.1",
"postcss-cssnext": "^2.4.0",
"postcss-import": "^8.0.2",
"postcss-reporter": "^2.0.0",
@@ -46,6 +47,7 @@
"stylelint-config-wikimedia": "0.4.1",
"sync-request": "^3.0.1",
"underscore": "^1.8.3",
+ "vinyl-paths": "^2.1.0",
"yargs": "^6.3.0"
}
}
--
To view, visit https://gerrit.wikimedia.org/r/389934
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7bf03b47d495b44a63f4d18bac9e484f15ad862a
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/portals
Gerrit-Branch: master
Gerrit-Owner: Jdrewniak <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits