working uploads
BIN
demo/media/Screen Shot 2020-05-05 at 12.54.27 PM-1-16x16.png
Normal file
|
After Width: | Height: | Size: 359 B |
BIN
demo/media/Screen Shot 2020-05-05 at 12.54.27 PM-1-320x240.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
demo/media/Screen Shot 2020-05-05 at 12.54.27 PM-1-640x480.png
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
demo/media/Screen Shot 2020-05-05 at 12.54.27 PM-1.png
Normal file
|
After Width: | Height: | Size: 110 KiB |
BIN
demo/media/Screen Shot 2020-05-05 at 12.54.27 PM-16x16.png
Normal file
|
After Width: | Height: | Size: 359 B |
BIN
demo/media/Screen Shot 2020-05-05 at 12.54.27 PM-320x240.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
demo/media/Screen Shot 2020-05-05 at 12.54.27 PM-640x480.png
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
demo/media/Screen Shot 2020-05-05 at 12.54.27 PM.png
Normal file
|
After Width: | Height: | Size: 110 KiB |
@@ -18,7 +18,7 @@ function getOutputImage(sourceImage, size) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = async function resizeAndSave(config, uploadConfig, savedFilename) {
|
module.exports = async function resizeAndSave(config, savedFilename) {
|
||||||
/**
|
/**
|
||||||
* Resize images according to image desired width and height and return sizes
|
* Resize images according to image desired width and height and return sizes
|
||||||
* @param config Object
|
* @param config Object
|
||||||
@@ -27,11 +27,13 @@ module.exports = async function resizeAndSave(config, uploadConfig, savedFilenam
|
|||||||
* @returns String[]
|
* @returns String[]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const sourceImage = `${config.staticDir}/${savedFilename}`;
|
const { imageSizes, staticDir } = config.upload;
|
||||||
|
|
||||||
|
const sourceImage = `${staticDir}/${savedFilename}`;
|
||||||
let sizes;
|
let sizes;
|
||||||
try {
|
try {
|
||||||
const dimensions = await sizeOf(sourceImage);
|
const dimensions = await sizeOf(sourceImage);
|
||||||
sizes = uploadConfig.imageSizes
|
sizes = imageSizes
|
||||||
.filter(desiredSize => desiredSize.width < dimensions.width)
|
.filter(desiredSize => desiredSize.width < dimensions.width)
|
||||||
.map(async (desiredSize) => {
|
.map(async (desiredSize) => {
|
||||||
const outputImage = getOutputImage(savedFilename, desiredSize);
|
const outputImage = getOutputImage(savedFilename, desiredSize);
|
||||||
@@ -41,7 +43,7 @@ module.exports = async function resizeAndSave(config, uploadConfig, savedFilenam
|
|||||||
// would it make sense for this to be set by the uploader?
|
// would it make sense for this to be set by the uploader?
|
||||||
position: desiredSize.crop || 'centre',
|
position: desiredSize.crop || 'centre',
|
||||||
})
|
})
|
||||||
.toFile(`${config.staticDir}/${imageNameWithDimensions}`);
|
.toFile(`${staticDir}/${imageNameWithDimensions}`);
|
||||||
return { ...desiredSize, filename: imageNameWithDimensions };
|
return { ...desiredSize, filename: imageNameWithDimensions };
|
||||||
});
|
});
|
||||||
const savedSizes = await Promise.all(sizes);
|
const savedSizes = await Promise.all(sizes);
|
||||||
|
|||||||