Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
payload-webp
Advanced tools
payloadcms/payload plugin for automatic image conversion to webp format.
npm i payload-webp
OR yarn add payload-webp
payload.config.ts
:import webp from "payload-webp";
// you may use this as fallback in your resizeOptsFactory
import { defaultResizeFactory } from "payload-webp";
export default buildConfig({
...
plugins: [
webp(webpPluginOptions)
]
)};
query {
allMedia {
docs {
url # url of original file [jpeg/png/webp]
filesize # filesize of original file
webp {
url # url of webp processed file [webp]
filesize # filesize of webp processed file
sizes {
thumbnail {
width
height
url
}
}
}
}
}
}
By default webp images are being processed to reduce their filesize as well.
Optionally you can pass JSON with following plugin options to tweak compression or limit conversion to particular mimeTypes or specific upload-enabled collections.
interface WebpPluginOptions {
/**
* Function that takes current image size to be resized and returns a sharp resize options object.
* Can be used to modify particular image size sizing, cropping, fitting etc.
*
* Example:
```JS
resize: (imageSize) => {
// fit to contain if image size is xs
if (imageSize.name === 'xs') {
return {
width: imageSize.width,
height: imageSize.width,
options: {
fit: "contain"
}
}
}
// fallback to payload's default behavior
return defaultResizeFactory(imageSize);
}
```*/
resizeOptsFactory?: (imageSize: ImageSize) => {
width: number;
height: number;
options?: sharp.ResizeOptions;
};
/**
* If present the main webp image will be sized to the given dimensions.
*/
maxResizeOpts?: { width?: number; height?: number; options?: sharp.ResizeOptions };
/**
* Which mime types convert to webp.
* Defaults to: ```["image/jpeg", "image/png", "image/webp"]```
*
* ***image/webp** is compressed*
*/
mimeTypes?: string[];
/**
* sharp webp options
* defaults to:
* ```
* {
* nearLossless: true,
* quality: 50,
* force: true,
* }```
*/
sharpWebpOptions?: sharp.WebpOptions;
/**
* Array of collection slugs that should have images converted to webp.
* By default all collections with upload property will convert images to webp.
*/
collections?: CollectionConfig['slug'][];
/**
* By default image conversion happens asynchronously in the background for faster UX.
* By switching this flag the hook and following request response will await for the image conversion.
*/
sync?: boolean;
/**
* When true log messages for debugging purposes.
*/
debug?: boolean;
/**
* Filename conflict behavior.
*
* When ```true``` the existing files will be overwritten.
*
* When ```false``` ```+i``` will be added to the filename.
*
*/
overwrite?: boolean;
}
You can regenerate existing images with following GraphQL mutation:
mutation {
WebpRegenerate(slug: String!, sort: String) {
currentFile
current
total
}
}
Argument | Description |
---|---|
slug | Upload collection slug in camelCase |
sort | You can pass the sort parameter to set the direction in which images will be regenerated. Default: createdAt |
You can use returned fields to show notify of current progress to user. Any subsequent call while regeneration of particular collection is in the progress will not start new regeneration process, but will return current progress.
You can access buffer objects of processed image and all image sizes from Express request object req.payloadWebp
. This way your adapter can store the files with external provider for an instance.
The maximum resolution webp file is at req.payloadWebp.src
, other file sizes are at their respective name req.payloadWebp[imageSizeName]
.
FAQs
payloadcms/payload plugin for automatic image conversion to webp format
The npm package payload-webp receives a total of 26 weekly downloads. As such, payload-webp popularity was classified as not popular.
We found that payload-webp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.