Upload the image in 3 formats only

Hello,

sorry for the late reply. :blush:

I finally have time to work on my project again. First I deleted two breakpoints (“medium”, “large”) because I only need “small”.

Then I optimized the original image using a method that I derived from “const generateThumbnail = async file => {...}” in “image-manipulation.js”.

// CUSTOM: GENERATE IMAGE - OPTIMIZE ORIGINAL FILE
const ORIGINAL_RESIZE_OPTIONS = {
  width: 800,
  height: 600,
  fit: 'inside',
};

const optimizeOriginal = async file => {
  if (!(await canBeProccessed(file.buffer))) {
    return null;
  }

  const { width, height } = await getDimensions(file.buffer);

  if (width >= ORIGINAL_RESIZE_OPTIONS.width || height >= ORIGINAL_RESIZE_OPTIONS.height) {

    const newBuff = await resizeTo(file.buffer, ORIGINAL_RESIZE_OPTIONS);

    if (newBuff) {

      const { width, height, size } = await getMetadatas(newBuff);

      return {
        name: file.name,
        hash: file.hash,
        ext: file.ext,
        mime: file.mime,
        width,
        height,
        size: bytesToKbytes(size),
        buffer: newBuff,
        path: file.path ? file.path : null,
        alternativeText: file.alternativeText,  // ORIGINAL PROPERTY
        related: file.related                   // ORIGINAL PROPERTY
      };
    }
  }

  return null;
};

and do not forget:

module.exports = {
  getDimensions,
  optimizeOriginal,   // CUSTOM: GENERATE IMAGE - OPTIMIZE ORIGINAL FILE
  generateThumbnail,
  generateResponsiveFormats,
  bytesToKbytes,
  optimize,
};

Then in the “Upload.js” in “async uploadFileAndPersist(fileData, { user } = {}) {...}”:

    ...
    } = strapi.plugins.upload.services['image-manipulation'];    

    // ---------------- CUSTOMIZATION (BEGIN) ---------------- //
    // CUSTOM: GENERATE IMAGE - OPTIMIZE ORIGINAL FILE
    const fileDataOptimized = await optimizeOriginal(fileData);

    if (fileDataOptimized) {
      fileData = fileDataOptimized;      
    }
    // ---------------- CUSTOMIZATION (END) ------------------ //

    await strapi.plugins.upload.provider.upload(fileData);
    ...

It works! I think this is a good solution! :beer:

Best regards and thanks to everyone! :+1: