grunt-responsive-images
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -43,2 +43,15 @@ /* | ||
}, | ||
no_files: { | ||
options: { | ||
sizes: [{ | ||
width: 320 | ||
}] | ||
}, | ||
files: [{ | ||
expand: true, | ||
src: ['no_files/**/*.{jpg,gif,png}'], | ||
cwd: 'test/assets/', | ||
dest: 'tmp/' | ||
}] | ||
}, | ||
file_wildcard_options: { | ||
@@ -289,2 +302,20 @@ options: { | ||
}] | ||
}, | ||
global_quality: { | ||
options: { | ||
quality: 80, | ||
sizes: [{ | ||
width: 320 | ||
},{ | ||
width: 640 | ||
},{ | ||
width: 1024 | ||
}] | ||
}, | ||
files: [{ | ||
expand: true, | ||
src: ['global_quality/**/*.{jpg,gif,png}'], | ||
cwd: 'test/assets/', | ||
dest: 'tmp/' | ||
}] | ||
} | ||
@@ -291,0 +322,0 @@ }, |
{ | ||
"name": "grunt-responsive-images", | ||
"description": "Produce images at different sizes for responsive websites.", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"homepage": "https://github.com/andismith/grunt-responsive-images", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -312,2 +312,14 @@ # grunt-responsive-images [](http://badge.fury.io/js/grunt-responsive-images) | ||
*0.1.2* | ||
* Quality can now be defined globally. | ||
* If no files are found, the task will now silently fail. | ||
* Bug fixes. | ||
* Ipsy upsy daisy dooooo. | ||
*0.1.1* | ||
* Added filters, useful for changing the resizing operation. | ||
* 100% more dinosaur. | ||
*0.1.0* | ||
@@ -314,0 +326,0 @@ |
@@ -26,2 +26,3 @@ /** | ||
separator: '-', | ||
quality: 100, // value between 1 and 100 | ||
sizes: [{ | ||
@@ -42,3 +43,2 @@ name: 'small', | ||
gravity: 'Center', // gravity for cropped images: NorthWest, North, NorthEast, West, Center, East, SouthWest, South, or SouthEast | ||
quality: 100, // value between 1 and 100 | ||
upscale: false // DEFAULT CHANGED - true/false | ||
@@ -81,3 +81,3 @@ }; | ||
*/ | ||
var setEngine = function(engine) { | ||
var getEngine = function(engine) { | ||
if (typeof GFX_ENGINES[engine] === 'undefined') { | ||
@@ -87,3 +87,8 @@ return grunt.fail.warn('Invalid render engine specified'); | ||
grunt.verbose.ok('Using render engine: ' + GFX_ENGINES[engine].name); | ||
gm.subClass({ imageMagick: (engine === 'im') }); | ||
if (engine === 'im') { | ||
return gm.subClass({ imageMagick: (engine === 'im') }); | ||
} | ||
return gm; | ||
}; | ||
@@ -139,2 +144,6 @@ | ||
var isValidQuality = function(quality) { | ||
return (quality > 1); | ||
}; | ||
/** | ||
@@ -327,2 +336,3 @@ * Create a name to suffix to our file. | ||
var done = this.async(); | ||
var gfxEngine = {}; | ||
var i = 0; | ||
@@ -338,3 +348,3 @@ var series = []; | ||
setEngine(options.engine); | ||
gfxEngine = getEngine(options.engine); | ||
@@ -348,7 +358,10 @@ options.units = _.extend(_.clone(DEFAULT_UNIT_OPTIONS), options.units); | ||
if (!isValidSize(sizeOptions.width, sizeOptions.height)) { | ||
return grunt.fail.fatal('Size is invalid (' + sizeOptions.width + ', ' + sizeOptions.height + ')'); | ||
// allow task to be by-passed if no images | ||
return grunt.log.warn('Size is invalid (' + sizeOptions.width + ', ' + sizeOptions.height + ')'); | ||
} | ||
if (sizeOptions.quality < 1) { | ||
return grunt.fail.warn('Quality configuration has changed to values between 1 - 100. Please update your configuration'); | ||
sizeOptions.quality = sizeOptions.quality || options.quality; | ||
if (!isValidQuality(sizeOptions.quality)) { | ||
return grunt.log.warn('Quality configuration has changed to values between 1 - 100. Please update your configuration'); | ||
} | ||
@@ -362,3 +375,3 @@ | ||
if (task.files.length === 0) { | ||
return grunt.fail.warn('Unable to compile; no valid source files were found.'); | ||
return grunt.log.warn('Unable to compile; no valid source files were found.'); | ||
} else { | ||
@@ -389,3 +402,3 @@ | ||
var image = gm(srcPath); | ||
var image = gfxEngine(srcPath); | ||
@@ -401,11 +414,15 @@ image.size(function(error, size) { | ||
// crop image | ||
if (!sizeOptions.aspectRatio && sizeOptions.width && sizeOptions.height) { | ||
// crop image | ||
sizingMethod = '^'; | ||
mode = 'crop'; | ||
} | ||
// upscale | ||
if (sizeOptions.upscale && (sizeOptions.width > size.width || sizeOptions.height > size.height)) { | ||
sizingMethod = '^'; | ||
// upscale | ||
if (sizeOptions.aspectRatio) { | ||
sizingMethod = '^'; | ||
} else { | ||
sizingMethod = '!'; | ||
} | ||
} | ||
@@ -412,0 +429,0 @@ |
@@ -38,6 +38,6 @@ /** | ||
var async = require('async'), | ||
grunt = require('grunt'), | ||
im = require('node-imagemagick'), | ||
q = require('q'); | ||
var async = require('async'); | ||
var gm = require('gm'); | ||
var grunt = require('grunt'); | ||
var q = require('q'); | ||
@@ -57,3 +57,3 @@ /** | ||
// load created image | ||
im.identify(actualPath + filename, function(error, actualProp) { | ||
gm(actualPath + filename).identify(function(error, actualProp) { | ||
if (error) { | ||
@@ -63,3 +63,3 @@ deferred.reject('Failed to load actual (created) image "' + actualPath + filename + '"'); | ||
// load expected image | ||
im.identify(expectedPath + filename, function(error, expectedProp) { | ||
gm(expectedPath + filename).identify(function(error, expectedProp) { | ||
if (error) { | ||
@@ -69,14 +69,14 @@ deferred.reject('Failed to load expected image "' + expectedPath + filename + '"'); | ||
// check if we have a match | ||
if ((actualProp.compression === expectedProp.compression) && | ||
(actualProp.width === expectedProp.width) && | ||
(actualProp.height === expectedProp.height) && | ||
(actualProp.quality === expectedProp.quality)) { | ||
if ((actualProp.Compression === expectedProp.Compression) && | ||
(actualProp.size.width === expectedProp.size.width) && | ||
(actualProp.size.height === expectedProp.size.height) && | ||
(actualProp['JPEG-Quality'] === expectedProp['JPEG-Quality'])) { | ||
deferred.resolve(true); | ||
} else { | ||
deferred.reject(filename + ': ' + | ||
'actual image (' + actualProp.compression + ' ' + actualProp.width + | ||
'x' + actualProp.height + ' - Q:' + actualProp.quality + | ||
'actual image (' + actualProp.compression + ' ' + actualProp.size.width + | ||
'x' + actualProp.size.height + ' - Q:' + actualProp.quality + | ||
') and ' + | ||
'expected image (' + expectedProp.compression + ' ' + expectedProp.width + | ||
'x' + expectedProp.height + ' - Q:' + expectedProp.quality + | ||
'expected image (' + expectedProp.compression + ' ' + expectedProp.size.width + | ||
'x' + expectedProp.size.height + ' - Q:' + expectedProp.quality + | ||
') should match'); | ||
@@ -284,2 +284,13 @@ } | ||
checkImages(actualPath, expectedPath, files, test); | ||
}, | ||
global_quality: function(test) { | ||
var actualPath = 'tmp/global_quality/', | ||
expectedPath = 'test/expected/global_quality/', | ||
files = [ | ||
'night_garden-320.jpg', | ||
'night_garden-640.jpg', | ||
'night_garden-1024.jpg' | ||
]; | ||
checkImages(actualPath, expectedPath, files, test); | ||
} | ||
@@ -286,0 +297,0 @@ }; |
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
20055301
371
0
92
1106