Cantaloupe Dynamic Image Server

repository·develop·Indexed 43 days ago

https://github.com/cantaloupe-project/cantaloupe

A high-performance dynamic image server written in Java designed to serve images on demand. It supports various formats and processing engines, featuring multiple caching implementations including S3, Redis, JDBC, Azure Storage, and an in-memory HeapCache.

Tokens
11.4K
Snippets
24
Records
54
Agent score
55%

What's inside Cantaloupe

  1. Configure Cantaloupe in an IDE

    develop

    To run Cantaloupe within an IDE (like IntelliJ IDEA or Eclipse):

    1. Create a new "Java Application" run configuration.
    2. Set the Main Class to edu.illinois.library.cantaloupe.StandaloneEntry.
    3. Add the following VM option to specify your configuration file: -Dcantaloupe.config=cantaloupe.properties.
  2. Upgrade from Cantaloupe 3.1.2 to 3.2

    develop

    Upgrading from version 3.1.2 to 3.2 involves adding new processor configuration keys and removing obsolete post-processor keys.

    Configuration Changes

    Add these keys from the sample configuration:

    • FfmpegProcessor.sharpen
    • GraphicsMagickProcessor.sharpen
    • ImageMagickProcessor.sharpen
    • JaiProcessor.sharpen
    • Java2dProcessor.upscale_filter
    • Java2dProcessor.downscale_filter
    • Java2dProcessor.sharpen
    • KakaduProcessor.upscale_filter
    • KakaduProcessor.downscale_filter
    • KakaduProcessor.sharpen
    • OpenJpegProcessor.upscale_filter
    • OpenJpegProcessor.downscale_filter
    • OpenJpegProcessor.sharpen
    • PdfBoxProcessor.upscale_filter
    • PdfBoxProcessor.downscale_filter
    • PdfBoxProcessor.sharpen
    • metadata.*

    Remove these obsolete keys:

    • Java2dProcessor.scale_mode
    • KakaduProcessor.post_processor.*
    • OpenJpegProcessor.post_processor.*
    • PdfBoxProcessor.post_processor.*
  3. Upgrade from 3.4.x to 4.0

    develop

    Upgrading from 3.4.x to 4.0 involves significant renaming and architectural changes.

    1. Configuration Renames

    • Any key containing Resolver $\rightarrow$ contains Source (e.g., HttpResolver $\rightarrow$ HttpSource).
    • HttpSource.auth.* $\rightarrow$ HttpSource.BasicLookupStrategy.auth.*
    • AmazonS3Source.* $\rightarrow$ S3Source.*
    • StreamProcessor.retrieval_strategy $\rightarrow$ processor.stream_retrieval_strategy
    • KakaduProcessor.path_to_binaries $\rightarrow$ KakaduDemoProcessor.path_to_binaries
    • AmazonS3Cache.* $\rightarrow$ S3Cache.*

    2. Configuration Additions

    Add these keys:

    • S3Source.endpoint
    • S3Source.BasicLookupStrategy.path_prefix
    • S3Source.BasicLookupStrategy.path_suffix
    • processor.fallback_retrieval_strategy
    • processor.imageio.*
    • S3Cache.endpoint
    • cache.server.source.ttl_seconds
    • cache.server.derivative.ttl_seconds

    3. Configuration Removals

    Remove these keys:

    • S3Source.bucket.region
    • processor.limit_to_8_bits
    • S3Cache.bucket.region
    • cache.server.source.enabled
    • cache.server.ttl_seconds

    4. Delegate Script and API Changes

    • Delegate Architecture: The 3.x script architecture is not compatible with 4.0. Refer to the
  4. Upgrade from Cantaloupe 2.2 to 3.0

    develop

    Upgrading from version 2.2 to 3.0 involves significant configuration renames, delegate script restructuring, and database schema changes.

    Configuration Changes

    Add these keys from the sample configuration:

    • admin.*
    • delegate_script.enabled
    • endpoint.iiif.2.restrict_to_sizes
    • StreamProcessor.retrieval_strategy
    • cache.source
    • AmazonS3Cache.*
    • AzureStorageCache.*
    • redaction.enabled

    Rename these keys:

    • delegate_script $\rightarrow$ delegate_script.pathname
    • cache.server $\rightarrow$ cache.derivative

    Remove these keys:

    • JdbcResolver.function.*

    Delegate Script Updates

    Add these methods from the sample delegate script:

    • redactions
    • Cantaloupe::JdbcResolver::get_database_identifier
    • Cantaloupe::JdbcResolver::get_media_type
    • Cantaloupe::JdbcResolver::get_lookup_sql

    Rename these delegate script methods:

    • Cantaloupe::get_pathname $\rightarrow$ Cantaloupe::FilesystemResolver::get_pathname
    • Cantaloupe::get_url $\rightarrow$ Cantaloupe::HttpResolver::get_url
    • Cantaloupe::get_azure_storage_blob_key $\rightarrow$ Cantaloupe::AzureStorageResolver::get_blob_key
    • Cantaloupe::get_s3_object_key $\rightarrow$ Cantaloupe::AmazonS3Resolver::get_object_key

    Note on JdbcResolver: If you use JdbcResolver, the JdbcResolver.function.* configuration keys are now obsolete. These functions must be rewritten as delegate script methods.

    Database Schema Changes

    If you are using JdbcCache, you must modify your database schema by renaming the last_modified column to last_accessed in the following tables:

    ALTER TABLE {JdbcCache.info_table} CHANGE COLUMN last_modified last_accessed;
    ALTER TABLE {JdbcCache.derivative_image_table} CHANGE COLUMN last_modified last_accessed;

    Admin Access

    Information previously available on the landing page (/) has moved to the Control Panel (/admin).

    • Username: admin
    • Password: Defined in the admin.password configuration option.
  5. Upgrade from 4.1.x to 5.0

    develop

    Upgrading from 4.1.x to 5.0 involves significant changes to packaging, requirements, and configuration.

    1. Environment and Packaging

    • Packaging: The application is now a JAR file and cannot run in a Servlet container.
    • Java Version: Java 11 or later is required.

    2. Configuration Changes

    Add these keys:

    • http.min_threads
    • http.max_threads
    • log_error_responses
    • meta_identifier.*
    • endpoint.iiif.3.enabled
    • endpoint.health.dependency_check
    • S3Source.region (Note: If you previously used S3Source.endpoint for an AWS endpoint, unset it and use this key instead)
    • processor.ManualSelectionStrategy.xpm
    • processor.downscale_linear
    • processor.imageio.xpm.reader
    • GrokProcessor.path_to_binaries
    • processor.pdf.*
    • S3Cache.region (Note: If you previously used S3Cache.endpoint for an AWS endpoint, unset it and use this key instead)
    • Logstash appender keys: log.application.ConsoleAppender.logstash.enabled, log.application.FileAppender.logstash.enabled, log.application.RollingFileAppender.logstash.enabled, log.error.FileAppender.logstash.enabled, log.error.RollingFileAppender.logstash.enabled

    Remove these keys:

    • http.http2.enabled
    • https.http2.enabled
    • scale_constraint_suffix.pattern
    • scale_constraint_suffix.format
    • endpoint.iiif.content_disposition
    • delegate_script.cache.enabled
    • processor.metadata.*
    • GraphicsMagickProcessor.path_to_binaries
    • KakaduDemoProcessor.path_to_binaries
    • ImageMagickProcessor.path_to_binaries
    • S3Cache.max_connections
    • redaction.enabled

    Rename these keys:

    • endpoint.iiif.2.restrict_to_sizes $\rightarrow$ endpoint.iiif.restrict_to_sizes
    • overlays.enabled $\rightarrow$ overlays.BasicStrategy.enabled

    3. Delegate Script Updates

    • New Methods: Add deserialize_meta_identifier(), serialize_meta_identifier(), pre_authorize(), extra_iiif3_information_response_keys(), and metadata().
    • Refactoring: The pre_authorize() method may require you to refactor logic previously handled in authorize().
    • Logger: Change references from edu.illinois.library.cantaloupe.script.Logger to edu.illinois.library.cantaloupe.delegate.Logger.
    • Metadata: If you used processor.metadata.preserve, switch to the metadata() delegate method.
    • Context Hash: The cookie key in the delegate script context hash is now a hash of cookie name-value pairs.

    4. API and Protocol Changes

    • Reverse Proxy Header: X-IIIF-ID is no longer supported. Use X-Forwarded-ID instead.
    • Scale Constraints: The default delimiter changed from a dash (-) to a semicolon (;). To maintain compatibility with URIs like image.jpg-1:2, set meta_identifier.transformer.StandardMetaIdentifierTransformer.delimiter to -.
    • Deprecated Query Args: page and time query arguments are deprecated. Use the identifier path component instead (e.g., image.jpg;3 for page 3, or image.jpg;10 for 10 seconds).

    5. Sources and Processors

    • HttpSource: The source HttpSource2 from 4.1.x is now HttpSource. The old HttpSource has been removed.
    • Kakadu: If using KakaduNativeProcessor, install the updated shared library from the deps folder.
    • KakaduDemoProcessor: This is no longer available. Switch to KakaduNativeProcessor, OpenJpegProcessor, or GrokProcessor.

    6. Cache Management

    • If using a derivative cache with non-zero orientations or embedded metadata for the new metadata() method, you must purge all cached infos (manually delete .json files/objects or purge the whole cache via API).
  6. Upgrade from Cantaloupe 3.2.x to 3.3

    develop

    Upgrading from version 3.2.x to 3.3 requires several configuration changes, key renames, and delegate script updates.

    Configuration Changes

    Add these keys from the sample configuration:

    • delegate_script.cache.enabled
    • endpoint.api.*
    • processor.dcm
    • processor.normalize
    • processor.background_color
    • processor.upscale_filter
    • processor.downscale_filter
    • processor.sharpen
    • processor.jpg.progressive
    • processor.jpg.quality
    • processor.tif.compression
    • cache.server.ttl_seconds
    • overlays.BasicStrategy.type
    • overlays.BasicStrategy.string
    • overlays.BasicStrategy.string.*

    Rename these keys:

    • watermark.* $\rightarrow$ overlays.*

    Remove these obsolete keys:

    • JdbcResolver.max_pool_size
    • FfmpegProcessor.sharpen
    • GraphicsMagickProcessor.sharpen
    • GraphicsMagickProcessor.background_color
    • ImageMagickProcessor.sharpen
    • ImageMagickProcessor.background_color
    • JaiProcessor.sharpen
    • JaiProcessor.jpg.quality
    • JaiProcessor.tif.compression
    • Java2dProcessor.upscale_filter
    • Java2dProcessor.downscale_filter
    • Java2dProcessor.sharpen
    • Java2dProcessor.jpg.quality
    • Java2dProcessor.tif.compression
    • KakaduProcessor.upscale_filter
    • KakaduProcessor.downscale_filter
    • KakaduProcessor.sharpen
    • OpenJpegProcessor.upscale_filter
    • OpenJpegProcessor.downscale_filter
    • OpenJpegProcessor.sharpen
    • PdfBoxProcessor.upscale_filter
    • PdfBoxProcessor.downscale_filter
    • PdfBoxProcessor.sharpen
    • FilesystemCache.ttl_seconds
    • JdbcCache.max_pool_size
    • JdbcCache.ttl_seconds
    • AmazonS3Cache.ttl_seconds
    • AzureStorageCache.ttl_seconds

    Cache Maintenance

    If you are using FilesystemCache, you must purge your cache after the upgrade.

    Delegate Script Updates

    • Argument Changes: If using authorized?() or watermark() delegate methods, the contents of the operations argument have changed. Refer to the new sample delegate script.
    • Return Value Change: For the watermark() method, the pathname key in the returned hash must be changed to image.
    • Method Renaming: Rename the watermark() delegate method to overlay().
  7. Upgrade from 5.0 to 6.0

    develop

    To upgrade Cantaloupe from version 5.0 to 6.0, perform the following steps:

    1. Update Configuration

    Add these keys from the sample configuration to your setup:

    • endpoint.health.enabled
    • HttpSource.proxy.http.host
    • HttpSource.proxy.http.port
    • HttpSource.BasicLookupStrategy.send_head_requests
    • processor.purge_incompatible_from_source_cache

    2. Update Delegate Scripts

    Add the following method to your sample delegate script:

    • jdbcsource_last_modified()

    3. Update Java Delegates

    If you are using a Java delegate, add the following method to your delegate class:

    • getJDBCSourceLastModified()
  8. Upgrade from 4.0.x to 4.1

    develop

    To upgrade from 4.0.x to 4.1, follow these steps:

    1. Configuration Renames

    • HttpSource.trust_all_certs $\rightarrow$ HttpSource.allow_insecure
    • processor.[format] $\rightarrow$ processor.ManualSelectionStrategy.[format]
    • processor.fallback $\rightarrow$ processor.ManualSelectionStrategy.fallback

    2. Configuration Additions

    Add these keys:

    • max_scale
    • HttpSource.chunking.*
    • S3Source.chunking.*
    • AzureStorageSource.chunking.*
    • processor.selection_strategy

    3. Configuration Removals

    Remove these keys:

    • allow_upscaling
    • endpoint.public.auth.*
    • S3Source.max_connections
    • processor.normalize

    4. Delegate Logic Migration

    • Authorization: If you implemented redirect() or authorized?(), migrate their logic into authorize() and remove the old methods.
    • Public Auth: If you used endpoint.public.auth.* keys, use the new authorize() delegate method instead.

    5. Deprecations

    • KakaduDemoProcessor is deprecated. Consider migrating to KakaduNativeProcessor or OpenJpegProcessor.
  9. Run Cantaloupe via Command Line

    develop

    To run Cantaloupe from the source code using Maven, first prepare a configuration file by copying the sample properties file. Then, use the exec:java goal to run the embedded web server.

    To build a standalone release JAR, use mvn clean package. You can then run the resulting JAR using the java command, ensuring you point to your configuration file via the -Dcantaloupe.config system property and use the edu.illinois.library.cantaloupe.StandaloneEntry main class.

    # 1. Prepare configuration
    cp cantaloupe.properties.sample cantaloupe.properties
    
    # 2. Build and run using Maven
    mvn clean compile exec:java -Dcantaloupe.config=cantaloupe.properties
    
    # 3. Alternatively, build a release JAR and run it directly
    mvn clean package -DskipTests
    java -cp cantaloupe-{version}.jar -Dcantaloupe.config=cantaloupe.properties edu.illinois.library.cantaloupe.StandaloneEntry
  10. Run tests using Docker Compose

    develop

    To avoid manually installing all dependencies required for the freedeps profile, use the provided docker-compose.yml file. This spins up all required services in containers and runs the tests in a separate container.

    Run the following command from the project root:

    docker-compose -f docker/{platform}/docker-compose.yml up --build --exit-code-from cantaloupe
  11. Understand S3Cache object key structure

    develop

    When using S3Cache, objects are stored in the S3 bucket using a specific naming convention based on their type:

    • Info objects: Stored under the info/ prefix. The key is the MD5 hash of the image identifier followed by .json.
      • Template: {S3CACHE_OBJECT_KEY_PREFIX}/info/{md5(identifier)}.json
    • Image objects: Stored under the image/ prefix. The key includes the MD5 hash of the image identifier and the MD5 hash of the operation list string representation.
      • Template: {S3CACHE_OBJECT_KEY_PREFIX}/image/{md5(identifier)}/{md5(op_list_string)}{extension}

    Note: The {extension} is derived from the preferred extension of the Encode operation in the OperationList (e.g., .jpg, .png).