Image Processor quickstart
Turn on Image Processor, cache each transformation separately, and request your first derived image in Azion Console, the Azion CLI, or the API.
This guide instructs you through requesting your first derived image from an Application. By the end you will have:
- Image Processor turned on for one Application.
- A cache setting that stores each transformation as its own object.
- A Rules Engine rule that sends image requests to Image Processor.
- A resized image returned from a URL you wrote.
Three entities and one URL carry that result, in this order. The Application has Image Processor turned on. The cache setting belongs to the Application and makes the cache store two different transformations as two different objects. The rule belongs to the Application, matches image requests, and applies both the cache setting and the Optimize Images behavior. The image URL then carries the transformation in its ims query string. A request that no rule matches is delivered unprocessed, so the rule is what makes the query string mean anything.
Prerequisites
Console
- An Azion account.
- An Application that already delivers images from an origin. To create one, refer to Applications quickstart.
- The path of one image the Application serves, so you can request it at the end.
- Access to Azion Console. To sign in, refer to Access Azion Console.
Turn on Image Processor and Application Accelerator
Image Processor is a Platform Resource that is off in a new Application. This stage turns on two Platform Resources.
Application Accelerator is the second for two reasons. The field that varies the cache by a query string belongs to it, and the cache setting uses that field. The rule in this guide also reads ${request_uri}, and Azion refuses a rule that reads it while Application Accelerator is off. Processing an image does not require Application Accelerator, but caching each transformation separately does.
Console
To turn on both Platform Resources in Azion Console:
Access Azion Console > Applications > your Application.
In the Modules section, turn on Image Processor, described as Enable dynamic image editing options.
The toggle is in the same section.
The Application now has both Platform Resources turned on, and the Optimize Images behavior is available to its rules.
Create a cache setting that varies on the ims query string
Without this step, the cache cannot tell one transformation from another. It may answer a request for a 400-pixel image with a 200-pixel one.
Console
To create the cache setting in Azion Console:
Access Azion Console > Applications > your Application.
In Name, enter images.
In the Cache section, set Cache Behavior to Override cache behavior.
In the Cache section, in Max Age, enter 31536000.
The panel is in the Application Accelerator section.
In Fields, enter ims.
The Application now has a cache setting that stores one object per distinct ims value.
For the rest of the fields a cache setting carries, including how long an object stays cached, refer to Cache settings.
Create a rule that sends image requests to Image Processor
The rule is what turns the query string into a transformation. It matches requests for image paths, applies the cache setting you created, and carries the Optimize Images behavior.
Console
To create the rule in Azion Console:
Access Azion Console > Applications > your Application.
In Name, enter Optimize images.
In the criteria, select ${request_uri}.
Enter \.(jpg|jpeg|gif|bmp|png|ico|webp|avif).
In the behaviors, select Set Cache Policy, then choose the images cache setting.
Every request for a path with one of those extensions now gets the images cache setting and the Optimize Images behavior. Image Processor transforms the image when its URL carries ims.
Request a derived image
Ask for a width and see the response change.
Request one of your images with an ims query string, replacing the host and the path with your own:
The response reports its status, its type, and its size:
Request the same image with no query string and compare the size. The resized response is smaller when the source image is wider than 400 pixels. Both responses can carry a different format from the file on your origin, because Image Processor converts images for browsers that accept another format, such as WEBP.
To confirm that Image Processor handled the response rather than the origin, read the headers:
A processed response carries x-ims: Enabled and the size of the source image before the transformation:
You now have an Application that transforms images on request, and a URL that describes the transformation.