Image Handler

Files

/engine/handler.image.php

Introduction

Image Handler is used by Index Gateway to return all image files to the user agent HTTP requests. Handler adds proper cache headers as well as supports on-demand image-editing, where it is possible to load an image file with specific resize algorithms and even image filtering. It also checks for files from overrides folder, which can be returned instead of the actual file.

Workflow

This script can only be executed through Index Gateway and it throws a 403 Forbidden message if accessed directly.

Image Handler checks for the presence of the requested file and if the same file exists in overrides folder. If the file exists in overrides folder, then that file is used as source instead.

If the image file does not exist, then Image Handler can return a 404 image placeholder rather than just a 404 Not Found header. This is supported if it is set in configuration.

Cache is one year by default, this duration can be changed in configuration file. It is also possible to return the file without cache by supplying the 'nocache' request parameter. If this is set then the image files are regenerated with every request.

A BASE64 encoded string of the resource is returned if dynamic variable 'base64' is provided in the request. This can be useful in some situations.

Handler returns a 304 Not Modified header if it detects that the user agent already has the latest version of that image file.

Image Handler takes specific parameters, that are separated by & symbol, in the file name. These parameters are used for on-demand image loading, such as for returning an image in a specific resolution or with a specific filtering. This on-demand image editing can be disabled in configuration.

On-demand image editing parameters and their range is also checked against configuration parameters and limits, which can limit the options that can be set for image loading. This helps to protect the system against some malicious attacks.

Image editing is done through Imager class and the result is also cached, so the same image does not have to be generated multiple times.

Image Handler returns proper cache, last-modified, expiring headers and more. It also adds robots directive headers based on configuration.

Image content, in its original or edited form, is pushed to user agent with the proper headers.

Image Handler also makes an entry in the log file about the request, if Logger is used.