Showing with 23 additions and 8 deletions.
  1. +23 −8 lib/themeroller.image.js
@@ -1,9 +1,11 @@
var _ = require( "underscore" ),
var imVersion,
_ = require( "underscore" ),
async = require( "async" ),
fs = require( "fs" ),
im = require( "gm" ).subClass({ imageMagick: true }),
logger = require( "simple-log" ).init( "download.jqueryui.com" ),
path = require( "path" ),
semver = require( "semver" ),
cache = {},
cacheCronTimeout,
cacheExpiresTime = 0,
@@ -152,14 +154,26 @@ generateIcon = function( params, callback ) {
color = hashColor( params.color );

// http://www.imagemagick.org/Usage/masking/#shapes
// IM 6.7.9 and below:
// $ convert <icons_mask_filename> -background <color> -alpha shape output.png
// IM > 6.7.9: (see #132 http://git.io/gfSacg)
// $ convert <icons_mask_filename> -set colorspace RGB -background <color> -alpha shape -set colorspace sRGB output.png

imageQueue.push(function( innerCallback ) {
try {
im( __dirname + "/../template/themeroller/icon/mask.png" )
.background( color )
.out( "-alpha", "shape" )
.stream( "png", stream2Buffer( innerCallback ) );
if ( semver.gt( imVersion, "6.7.9" ) ) {
im( __dirname + "/../template/themeroller/icon/mask.png" )
.out( "-set", "colorspace", "RGB" )
.background( color )
.out( "-alpha", "shape" )
.out( "-set", "colorspace", "sRGB" )
.stream( "png", stream2Buffer( innerCallback ) );
} else {
im( __dirname + "/../template/themeroller/icon/mask.png" )
.background( color )
.out( "-alpha", "shape" )
.stream( "png", stream2Buffer( innerCallback ) );
}
} catch( err ) {
return innerCallback( err );
}
@@ -331,7 +345,7 @@ Image.prototype = {
}
};

// Check the ImageMagick installation using node-gm (in a hack way).
// Check the ImageMagick installation using node-gm (in a hacky way).
async.series([
function( callback ) {
var wrappedCallback = function( err ) {
@@ -352,8 +366,9 @@ async.series([
if ( !(/ImageMagick/).test( output ) ) {
return callback( new Error( "ImageMagick not installed.\n" + output ) );
}
if ( !(/\s6\.6/).test( output ) ) {
return callback( new Error( "ImageMagick version is incorrect, it's not 6.6.\n" + output ) );
imVersion = output.split( "\n" )[ 0 ].replace( /^Version: ImageMagick ([^ ]*).*/, "$1" );
if ( !semver.valid( imVersion ) ) {
return callback( new Error( "Could not identify ImageMagick version.\n" + output ) );
}
callback();
}));