Files
2023-06-30 15:24:16 +02:00

2.7 KiB

Image CDN

Image CDN is a lightweight image caching and resizing server written in Go. It provides a simple HTTP interface for fetching and resizing images on the fly.

Features

  • Caches images in Redis for improved performance
  • Supports resizing images based on width, height, and percentage
  • Handles multiple authorized hosts
  • Supports PNG, JPEG, and WebP image formats

Getting Started

To get started with Image CDN, follow these steps:

  1. Clone the repository:
git clone https://git.rznet.fr/razian/imgcdn
cd imgcdn
  1. Build the container:
docker build -t imgcdn .
  1. Start the container:
docker run -d -p 8080:8080 --name imgcdn imgcdn

Now, the Image CDN server is up and running on port 8080.

Configuration

The Image CDN server can be configured using command-line arguments. Here are the available configuration options:

  • --config (optional): Path to a file containing a list of authorized hosts (one host per line)
  • --redis (optional): Enable or disable Redis caching (true or false; default: true)
  • --redishost (optional): Hostname of the Redis server (default: localhost)
  • --redisport (optional): Port of the Redis server (default: 6379)

You can pass these arguments while starting the container:

docker run -d -p 8080:8080 --name imgcdn imgcdn --config=hosts.cfg --redis=true --redishost=redis

Usage

Once the Image CDN server is running, you can access the images using the following URL pattern:

http://<server>:8080/<path-to-image>?w=<width>&h=<height>&p=<percentage>
  • <server>: The hostname or IP address of the server where the Image CDN is running
  • <path-to-image>: The path to the image on the server
  • <width> (optional): The desired width of the resized image
  • <height> (optional): The desired height of the resized image
  • <percentage> (optional): The percentage of the original image size for resizing (0-100)

For example, to resize an image to a width of 200 pixels:

http://<server>:8080/images/photo.jpg?w=200

Redis Caching

By default, Image CDN uses Redis to cache images for improved performance. If Redis caching is enabled (--redis=true), the server will store resized images in Redis for subsequent requests. If Redis caching is disabled (--redis=false), the server will fetch the original image from the URL for each request.

Authorized Hosts

Image CDN supports restricting requests to specific authorized hosts. You can provide a file containing a list of authorized hosts using the --config command-line argument. Each host should be listed on a separate line in the file.

License

This project is licensed under the MIT License. See the LICENSE file for more information.