🐛 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:
parent
b4654b19d5
commit
010d787046
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user