This manual refers to a future version of the software that is still in development. It may be incomplete or inaccurate and the software may change before a final release.


The overlay feature overlays an image or text string on top of a derivative (output) image. This can be useful for description, branding, attribution, copyright notices, and so on.

With all types of overlays, the position, inset, and output width/height threshold (below which the overlay won't be displayed) are configurable.

Not all processors support overlays; see the table of supported features.

Image Overlays

An image overlay must be a 24-bit RGB or RGBA PNG image. It will be blended pixel-for-pixel into the output image.

Overlay images can be located on the filesystem or on a web server. Regardless, they are cached in memory after being loaded the first time, so there is no performance penalty for using web-hosted overlay images.

When using multiple image overlays, their filenames must all be different, regardless of where they reside.

Sample overlay image (PNG)

Image with image overlay applied.
overlays.strategy = BasicStrategy
overlays.BasicStrategy.type = image
overlays.BasicStrategy.image = /path/to/image.png
overlays.BasicStrategy.position = bottom right
Image with repeating image overlay applied.
overlays.strategy = BasicStrategy
overlays.BasicStrategy.type = image
overlays.BasicStrategy.image = /path/to/image.png
overlays.BasicStrategy.position = repeat
Image with scaled image overlay applied.
overlays.strategy = BasicStrategy
overlays.BasicStrategy.type = image
overlays.BasicStrategy.image = /path/to/image.png
overlays.BasicStrategy.position = scaled

String Overlays

String overlays are dynamically rendered onto an image using Java 2D. The font family, size, weight, color, stroke color, background color and opacity, etc., are configurable.

Line breaks within the string (\n) are respected, enabling multi-line strings. Each line is auto-aligned to the edge of the image according to the overlay position.

Strings will never overflow the image. When a string doesn't fit entirely inside at its specified font size, the application will try to use the largest font size that fits, down to the configurable minimum allowed size. If none fit, the string won't be drawn.

Image with string overlay applied.
overlays.strategy = BasicStrategy
overlays.BasicStrategy.type = string
overlays.BasicStrategy.string = McKinley Marina\nMilwaukee, Wisconsin, USA
overlays.BasicStrategy.string.color = white
overlays.BasicStrategy.string.background.color = rgba(0,0,0,0.5)
overlays.BasicStrategy.position = bottom left
overlays.BasicStrategy.inset = 10

To get a list of all available fonts, start the JVM with the -list-fonts command-line argument:

java -jar cantaloupe.jar -list-fonts

Modes of Operation

The overlay system offers two "strategies," or modes of operation: a basic strategy, where overlay properties are hard-coded in the configuration file and applied to all requests; and a script strategy, where the decision of whether to apply an overlay, and what kind, depends on the return value of a delegate method. The overlays.strategy configuration key is used to set the strategy.


With BasicStrategy, the overlays.BasicStrategy.* keys in the configuration file are used to set an overlay type (image or string), position, inset, and others. This strategy is easy to configure and is all that is needed when it is intended for the same overlay to be applied to all images.


Perhaps you want to apply an image overlay to some of your images, and to others, you want to apply a string overlay, or no overlay. Perhaps you want to control overlays based on the client's IP address or user agent. Or, perhaps you only want to apply overlays to JPEG output images, and not GIFs. Or, perhaps you don't want to apply an overlay to images that have been rotated. All of this is possible by writing just a few lines of code.

With the overlay() delegate method, you can tell the application whether to apply an overlay in response to a particular request, and what its properties should be. As an example:

class CustomDelegate
  # If the resulting image is less than this many pixels on a side, don't
  # apply an overlay.

  def overlay(options = {})
    resulting_size = context['resulting_size']
    return nil if resulting_size['width'] < MIN_SIZE_CUTOFF or
        resulting_size['height'] < MIN_SIZE_CUTOFF

    # Don't render an overlay for clients on localhost.
    return nil if %w( ::1/128).include?(context['client_ip'])

    # Don't render an overlay on GIF images.
    return nil if context['output_format'] == 'image/gif'

    # Don't render an overlay on images of cantaloupes.
    return nil if context['identifier'].downcase.include?('cantaloupe')

    # Render an image overlay for iOS clients.
    if context['request_headers'].
        select{ |k,v| k.downcase == 'user-agent' and v.include?('iOS') }.any?
      return {
        'image' => '/path/to/ios-overlay.png',
        'position' => 'bottom right',
        'inset' => 5

    # Render a string overlay for all other clients.
      'string' => "This string\nhas multiple lines",
      'position' => 'bottom left',
      'inset' => 5,
      'font' => 'Helvetica',
      'font_size' => 20,
      'font_min_size' => 18,
      'font_weight' => 1.0,
      'color' => 'white',
      'background_color' => 'rgba(0, 0, 0, 0.6)'
      'glyph_spacing' => 0,
      'stroke_color' => 'black',
      'stroke_width' => 1


Position and inset are configurable. Supported positions are top left, top center, top right, left center, center, right center, bottom left, bottom center, and bottom right. Image overlays also support repeat and scaled. All positions except repeat support an inset.

With Zooming Viewers

Zooming image viewers display a mosaic of cropped image tiles. There are a few techniques that can prevent each tile from receiving an overlay:

  • Set the overlays.BasicStrategy.output_width_threshold and overlays.BasicStrategy.output_height_threshold configuration options to values that are slightly larger than the tile size used by the image viewer. This will disable overlays for images the size of image viewer tiles, and enable them for anything larger. Be aware, though, that the tile size used by the viewer may differ depending on the source image.
  • Have the zooming viewer supply a URI query argument, and check for it in the overlay() delegate method. Of course, a user could figure this out and supply the same argument in other image requests.
  • Using ScriptStrategy, return nil if a crop operation is present in the operation list. Example:
    class CustomDelegate
      def overlay(options = {})
        return nil if context['operations'].find{ |op| op['class'].include?('Crop') }
        # ...