mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 13:19:44 +02:00
feat: Preserve original format of images, change interpolation kernel
Closes #349
This commit is contained in:
parent
b82a601f46
commit
0a5210dd21
17 changed files with 212 additions and 103 deletions
|
@ -17,29 +17,36 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const image = sharp(inputs.file.fd);
|
||||
const image = sharp(inputs.file.fd, {
|
||||
animated: true,
|
||||
});
|
||||
|
||||
let metadata;
|
||||
try {
|
||||
await image.metadata();
|
||||
metadata = await image.metadata();
|
||||
} catch (error) {
|
||||
throw 'fileIsNotImage';
|
||||
}
|
||||
|
||||
if (['svg', 'pdf'].includes(metadata.format)) {
|
||||
throw 'fileIsNotImage';
|
||||
}
|
||||
|
||||
const dirname = uuid();
|
||||
const rootPath = path.join(sails.config.custom.projectBackgroundImagesPath, dirname);
|
||||
|
||||
fs.mkdirSync(rootPath);
|
||||
|
||||
const extension = metadata.format === 'jpeg' ? 'jpg' : metadata.format;
|
||||
|
||||
try {
|
||||
await image.jpeg().toFile(path.join(rootPath, 'original.jpg'));
|
||||
await image.toFile(path.join(rootPath, `original.${extension}`));
|
||||
|
||||
await image
|
||||
.resize(336, 200)
|
||||
.jpeg({
|
||||
quality: 100,
|
||||
chromaSubsampling: '4:4:4',
|
||||
.resize(336, 200, {
|
||||
kernel: sharp.kernel.nearest,
|
||||
})
|
||||
.toFile(path.join(rootPath, 'cover-336.jpg'));
|
||||
.toFile(path.join(rootPath, `cover-336.${extension}`));
|
||||
} catch (error1) {
|
||||
try {
|
||||
rimraf.sync(rootPath);
|
||||
|
@ -58,6 +65,7 @@ module.exports = {
|
|||
|
||||
return {
|
||||
dirname,
|
||||
extension,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue