Configure Image Processor on an application
Turn on Image Processor and create a Rules Engine rule that optimizes and caches images by the ims query string, from Console, API v4, or API v3.
You configure Image Processor on an application from Azion Console, the Azion API v4, or the Azion API v3. For a first look at the product, refer to the Image Processor quickstart.
Prerequisites
- An application. To create one, refer to Applications quickstart.
- Access to Azion Console, for the Console procedure. Refer to Access Azion Console.
- A personal token, for the API procedures.
Configure through Azion Console
To turn on Image Processor and Application Accelerator:
Access Azion Console > Applications > your application.
The application runs with both modules. Application Accelerator is required to vary the cache on the ims query string, because the Cache vary by Query String control sits in the cache setting’s Application Accelerator section. It is not required to process an image.
To create the cache setting that gives the derived images a time-to-live (TTL) and varies the cache key by ims:
Access Azion Console > Applications > your application, then go to the Cache Settings tab.
In Name, enter a name that identifies the setting. For example: Images.
Under Browser Cache, select Override cache settings.
Set Max Age under Browser Cache to the duration the browser keeps the image.
Under Cache, select Override cache behavior.
Set Max Age under Cache to a long duration. Images change less often than other content, so a long duration reduces requests to the origin. Refer to Cache Settings for the maximum you can set.
Under Application Accelerator, open Cache vary by Query String and set Behavior to Allowlist.
In Fields, enter ims.
Turn on Sort to keep the cache key consistent regardless of the order the query string parameters arrive in.
The cache setting appears in the Cache Settings tab, with a long TTL and the cache key varying by the ims field.
To create the rule that applies the cache setting and optimizes images:
Enter a name for the rule. For example: Optimize images.
In the Criteria section, select the ${request_uri} variable.
Enter \.(jpg|jpeg|gif|bmp|png|ico|webp|avif) as the argument.
Requests whose URI matches the argument carry the cache setting and run through Image Processor. To confirm that an image is optimized, inspect the page with your browser’s developer tools and find the request for the image. The query string carries ims=<width>x<height>, the resolution requested; remove the query string to load the original file.
Configure through the Azion API v4
To turn on Image Processor and Application Accelerator, send a PATCH request, replacing [TOKEN VALUE] with your personal token and <application_id> with your application ID:
Read back, the application carries the following modules:
Application Accelerator is required to vary the cache on the ims query string, because that field belongs to modules.application_accelerator in a cache setting. It is not required to process an image.
To create the cache setting that gives the derived images a time-to-live (TTL) and varies the cache key by ims, send a POST request:
For every field a cache setting carries, refer to Cache Settings.
The response returns the cache setting Azion created:
Copy the id value. To create the rule that applies the cache setting and optimizes images, replacing <cache_setting_id> with the ID you copied, send a POST request:
The response echoes the criteria and behaviors Azion accepted:
Requests whose URI matches the argument carry the cache setting and run through Image Processor. To confirm that an image is optimized, inspect the page with your browser’s developer tools and find the request for the image. The query string carries ims=<width>x<height>, the resolution requested; remove the query string to load the original file.
Configure through the Azion API v3
To turn on Image Processor and Application Accelerator, send a PATCH request, replacing [TOKEN VALUE] with your personal token and <application_id> with your application ID:
The response returns the updated value.
Application Accelerator is required to vary the cache on the ims query string. It is not required to process an image.
To create the cache setting that gives the derived images a time-to-live (TTL) and varies the cache key by ims, send a POST request:
For every field a cache setting carries, refer to Cache Settings.
The response returns the cache setting Azion created:
Copy the id value. To create the rule that applies the cache setting and optimizes images, replacing <cache_setting_id> with the ID you copied, send a POST request:
The response returns the rule Azion created:
Requests whose URI matches either argument carry the cache setting and run through Image Processor. To confirm that an image is optimized, inspect the page with your browser’s developer tools and find the request for the image. The query string carries ims=<width>x<height>, the resolution requested; remove the query string to load the original file.
Next steps
- Image Processor URL parameters - the full
imsgrammar for resize, crop, rotate, filters, and format conversion. - Image Processor settings - every field the module and its cache setting carry, with their values and defaults.
- Applications limits - the maximum size and dimensions Image Processor accepts.
- Cache Settings - every field a cache setting carries, including the maximum TTL.
- Optimize images for websites and mobile apps - an image path that resizes on request, caches every variant, and serves a fixed set of sizes.