🐛 Fixed responsive images for gifs & svgs (#10315)

closes #10301

* Redirected to original image for gifs & svgs

* Created canTransformFileExtension method

* Updated image middlewares to use canTransformFileExtension
This commit is contained in:
Fabien O'Carroll 2019-01-03 16:28:37 +07:00 committed by Hannah Wolfe
parent b4654b19d5
commit 010d787046
2 changed files with 28 additions and 0 deletions

View File

@ -36,6 +36,12 @@ const unsafeResizeImage = (originalBuffer, {width, height} = {}) => {
});
};
// NOTE: .gif optimization is currently not supported by sharp but will be soon
// as there has been support added in underlying libvips library https://github.com/lovell/sharp/issues/1372
// As for .svg files, sharp only supports conversion to png, and this does not
// play well with animated svg files
const canTransformFileExtension = ext => !['.gif', '.svg', '.svgz'].includes(ext);
const makeSafe = fn => (...args) => {
try {
require('sharp');
@ -55,5 +61,6 @@ const makeSafe = fn => (...args) => {
});
};
module.exports.canTransformFileExtension = canTransformFileExtension;
module.exports.process = makeSafe(unsafeProcess);
module.exports.resizeImage = makeSafe(unsafeResizeImage);

View File

@ -12,6 +12,27 @@ describe('lib/image: manipulator', function () {
testUtils.unmockNotExistingModule();
});
describe('canTransformFileExtension', function () {
it('returns false for ".gif"', function () {
should.equal(
manipulator.canTransformFileExtension('.gif'),
false
);
});
it('returns false for ".svg"', function () {
should.equal(
manipulator.canTransformFileExtension('.svg'),
false
);
});
it('returns false for ".svgz"', function () {
should.equal(
manipulator.canTransformFileExtension('.svgz'),
false
);
});
});
describe('cases', function () {
let sharp, sharpInstance;