Example tasks
Process images using Sharp
This example demonstrates how to process images using the Sharp library with Trigger.dev.
Overview
This task processes and watermarks an image using the Sharp library, and then uploads it to R2 storage.
Prerequisites
- A project with Trigger.dev initialized
- The Sharp library installed on your machine
- An R2-compatible object storage service, such as Cloudflare R2
Adding the build configuration
To use this example, you’ll first need to add these build settings to your trigger.config.ts
file:
trigger.config.ts
Any packages that install or build a native binary should be added to external, as native binaries cannot be bundled.
Key features
- Resizes a JPEG image to 800x800 pixels
- Adds a watermark to the image, positioned in the bottom-right corner, using a PNG image
- Uploads the processed image to R2 storage
Task code
trigger/sharp-image-processing.ts
Testing your task
To test this task in the dashboard, you can use the following payload:
Local development
To test this example task locally, be sure to install any packages from the build extensions you added to your trigger.config.ts
file to your local machine. In this case, you need to install .
Was this page helpful?