mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
🐛 Fixed gif images are not converted to png (#9853)
refs #9848 - Disabled image optimization for .gif files as a temporary solution until sharp library starts supporting latest version of libvips - Disabled image optimization for .svg/.svgz files as permanent solution as these file types are being converted to .png
This commit is contained in:
parent
c679a3527a
commit
9613de7cc1
2 changed files with 22 additions and 6 deletions
|
@ -7,7 +7,11 @@ const image = require('../../../lib/image');
|
||||||
module.exports = function normalize(req, res, next) {
|
module.exports = function normalize(req, res, next) {
|
||||||
const imageOptimizationOptions = config.get('imageOptimization');
|
const imageOptimizationOptions = config.get('imageOptimization');
|
||||||
|
|
||||||
if (!imageOptimizationOptions.resize) {
|
// 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
|
||||||
|
if (!imageOptimizationOptions.resize || ['.gif', '.svg', '.svgz'].includes(req.file.ext)) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,8 @@ describe('normalize', function () {
|
||||||
req = {
|
req = {
|
||||||
file: {
|
file: {
|
||||||
name: 'test',
|
name: 'test',
|
||||||
path: '/test/path'
|
path: '/test/path',
|
||||||
|
ext: '.jpg'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ describe('normalize', function () {
|
||||||
it('should do manipulation by default', function (done) {
|
it('should do manipulation by default', function (done) {
|
||||||
image.manipulator.process.resolves();
|
image.manipulator.process.resolves();
|
||||||
|
|
||||||
normalize(req, res, () => {
|
normalize(req, res, function () {
|
||||||
image.manipulator.process.calledOnce.should.be.true();
|
image.manipulator.process.calledOnce.should.be.true();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -39,7 +40,7 @@ describe('normalize', function () {
|
||||||
it('should add files array to request object with original and processed files', function (done) {
|
it('should add files array to request object with original and processed files', function (done) {
|
||||||
image.manipulator.process.resolves();
|
image.manipulator.process.resolves();
|
||||||
|
|
||||||
normalize(req, res, () => {
|
normalize(req, res, function () {
|
||||||
req.files.length.should.be.equal(2);
|
req.files.length.should.be.equal(2);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -52,13 +53,13 @@ describe('normalize', function () {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
normalize(req, res, () => {
|
normalize(req, res, function () {
|
||||||
image.manipulator.process.called.should.be.false();
|
image.manipulator.process.called.should.be.false();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call manipulation when resize flag is explicitly set', function (done) {
|
it('should not create files array when processing fails', function (done) {
|
||||||
image.manipulator.process.rejects();
|
image.manipulator.process.rejects();
|
||||||
|
|
||||||
normalize(req, res, ()=> {
|
normalize(req, res, ()=> {
|
||||||
|
@ -68,4 +69,15 @@ describe('normalize', function () {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
['.gif', '.svg', '.svgz'].forEach(function (extension) {
|
||||||
|
it(`should skip processing when file extension is ${extension}`, function (done) {
|
||||||
|
req.file.ext = extension;
|
||||||
|
normalize(req, res, function () {
|
||||||
|
req.file.should.not.be.equal(undefined);
|
||||||
|
should.not.exist(req.files);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue