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 the module.
- A resized image returned from a URL you wrote.
Four objects carry that result, and each one is linked to the one before it. The application holds the module switch. The cache setting belongs to the application and decides that two different transformations are two different cached 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.
Select the interface you will use. The prerequisites and every stage below follow that choice.
Prerequisites
- 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
The module is a switch on the application, and it is off until you set it. This stage turns on two modules.
Application Accelerator is the second for one reason: the field that varies the cache by a query string belongs to it, and the cache setting uses that field. Processing an image does not require the module, but caching each transformation separately does.
To turn on both modules in Azion Console:
Access Azion Console > Applications, then select the application that delivers your images.
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 carries both modules, and the Optimize Images behavior becomes 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, and it may answer a request for a 400 pixel image with a 200 pixel one.
To create the cache setting in Azion Console:
In Name, enter images.
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 the module
The rule is what turns the query string into a transformation. It matches requests for image paths, applies the cache setting you created, and adds the Optimize Images behavior.
To create the rule in Azion Console:
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 ending in one of those extensions now reaches Image Processor, carries the images cache setting, and is processed when its URL asks for a transformation.
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 processed response is smaller, and it may also carry a different format from the file on your origin, because Image Processor delivers WEBP to the browsers that accept it.
To confirm the module 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.