I want to generate .webp
image formats on image upload and keep the original image format.
When I make direct modification in /node_modules/strapi-plugin-upload/services/image-manipulation.js
everything works as expected. All breakpoints and thumbnail formats images generated and linked on REST API.
But when I copy Upload.js
and image-manipulation.js
to the extensions
folder, there is no thumbnail format of the image on REST API. However, all thumbnails are in the upload
folder.
// extensions/upload/services/Upload.js
...
- const { bytesToKbytes } = require('../utils/file');
+ const { bytesToKbytes } = require("strapi-plugin-upload/utils/file");
...
// extensions/upload/services/image-manipulation.js
...
const resizeTo = (buffer, options) =>
sharp(buffer)
+ .webp()
.resize(options)
.toBuffer()
.catch(() => null);
...
// on generateThumbnail and generateBreakpoint methods
return {
name: `thumbnail_${file.name}`,
hash: `thumbnail_${file.hash}`,
- ext: file.ext,
+ ext: ".webp",
- mime: file.mime,
+ mime: "image/webp",
width,
height,
size: bytesToKbytes(size),
buffer: newBuff,
path: file.path ? file.path : null,
};
What am I missing?
System Information
- Strapi Version: 3.2.5
- Operating System: Windows 10
- Database: sqlite3 (latest)
- Node Version: 14.15.0
- NPM Version: 6.14.8
- Yarn Version: 1.22.5