{"id":13513943,"url":"https://github.com/pch/mediator","last_synced_at":"2026-03-10T12:01:37.719Z","repository":{"id":226374862,"uuid":"768503086","full_name":"pch/mediator","owner":"pch","description":"🎨 Image resizing \u0026 media service: thumbnails, image effects, crop, proxy.","archived":false,"fork":false,"pushed_at":"2025-05-06T06:49:17.000Z","size":56,"stargazers_count":28,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-10T09:47:45.577Z","etag":null,"topics":["docker","golang","image","image-processing","image-server","images","libvips","webp"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-03-07T07:51:32.000Z","updated_at":"2025-05-09T05:23:48.000Z","dependencies_parsed_at":"2025-05-06T07:49:03.395Z","dependency_job_id":null,"html_url":"https://github.com/pch/mediator","commit_stats":null,"previous_names":["pch/mediator"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/pch/mediator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pch%2Fmediator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pch%2Fmediator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pch%2Fmediator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pch%2Fmediator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pch","download_url":"https://codeload.github.com/pch/mediator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pch%2Fmediator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30332853,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T05:25:20.737Z","status":"ssl_error","status_checked_at":"2026-03-10T05:25:17.430Z","response_time":106,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","golang","image","image-processing","image-server","images","libvips","webp"],"created_at":"2024-08-01T05:00:40.755Z","updated_at":"2026-03-10T12:01:37.698Z","avatar_url":"https://github.com/pch.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# Mediator\n\nMediator is a small, standalone service for efficient image processing and media file proxying.\n\nImages are processed on the fly with `libvips` and cached by CDN. The service is intended as a replacement for all common image operations in your web apps.\n\nYou can use it to:\n\n- **Resize images.** Generate thumbnails and responsive images on the fly.\n- **Crop images**. Crop images (currently only smart crop is supported).\n- **Apply effects**. Apply filters to images (currently only `pixelate` is supported).\n- **Strip metadata**. Remove metadata from images to reduce file size and protect user privacy.\n- **Proxy rendered content**. Render PDF and screenshot files using private, external services and wrap the response in a signed, cacheable URL.\n\n### Examples\n\n| Image                                                                                                                                                                                                  | URL                                                                                                                                                                                               | Description                       |\n| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- |\n| ![](https://cdn.pixelpeeper.com/image/transform/images/images/2024/02/2431ckhy8z9s1tya4trk21pb3f.jpg?h=300\u0026s=05eaeaef8aac014ab3d0797c031bffadd5ec475a4166a81197e20cd9a84ca070\u0026w=300)                   | https://cdn.pixelpeeper.com/image/transform/images/images/2024/02/2431ckhy8z9s1tya4trk21pb3f.jpg?h=300\u0026s=05eaeaef8aac014ab3d0797c031bffadd5ec475a4166a81197e20cd9a84ca070\u0026w=300                   | Fit to 300x300, keep aspect ratio |\n| ![](https://cdn.pixelpeeper.com/image/transform/images/images/2024/02/2431ckhy8z9s1tya4trk21pb3f.jpg?h=300\u0026op=fit%2Cpixelate\u0026s=f461358f29c70c7b189c30de875597dddcd7a7f5ff5dd528f0069c501ce028cd\u0026w=300) | https://cdn.pixelpeeper.com/image/transform/images/images/2024/02/2431ckhy8z9s1tya4trk21pb3f.jpg?h=300\u0026op=fit%2Cpixelate\u0026s=f461358f29c70c7b189c30de875597dddcd7a7f5ff5dd528f0069c501ce028cd\u0026w=300 | Fit to 300x300, pixelate          |\n| ![](https://cdn.pixelpeeper.com/image/transform/images/images/2024/02/2431ckhy8z9s1tya4trk21pb3f.jpg?h=300\u0026op=smartcrop\u0026s=80045b3f38f75772a5c78c65e5412db00b749c46cd2eb14d7411b246c2a3f2a7\u0026w=300)      | https://cdn.pixelpeeper.com/image/transform/images/images/2024/02/2431ckhy8z9s1tya4trk21pb3f.jpg?h=300\u0026op=smartcrop\u0026s=80045b3f38f75772a5c78c65e5412db00b749c46cd2eb14d7411b246c2a3f2a7\u0026w=300      | Smart crop                        |\n\nSee also: [example code](https://github.com/pch/mediator/tree/main/examples)\n\n## Features\n\n- **Fast**. Written in Go and uses `libvips` for image processing.\n- **Simple**. A small web service with minimal configuration.\n- **Secure**. Supports signed URLs and authentication tokens.\n- **Easy to integrate**. Works with any CDN and storage provider.\n- **Easy to deploy**. Just use the provided Docker image.\n- **Most common image operations**. Resize, crop, apply effects, and more.\n- **Auto WebP**. Auto-convert images to WebP and serve them to browsers that support it.\n- **PDF preview**. Generate preview images for PDF files.\n\n## Considerations\n\n- **Limited features**. Mediator aims to be cover the most common use cases. If you need more advanced features, consider a) contributing to the project, or b) using an alternative service.\n- **New software**. Although Mediator had been running in production without issues, it's still a new project, shaped by limited use cases.\n\n## Installation\n\nMediator is distributed as a docker image:\n\n```shell\ndocker run --rm -it --env-file .env --publish 8000:8000 ghcr.io/pch/mediator:latest\n```\n\n### Caching\n\nMediator does not offer a built-in cache and will re-download images on each request. The service is intended to run behind a CDN, which will cache the processed images.\n\n## Usage\n\n### Transforming images\n\nTo transform an image, use the `/image/transform/:source/:path` endpoint. The `:source` parameter is the name of the source, and `:path` is the path to the image file (e.g. S3 key/path).\n\n#### Request params\n\nThe `/image/transform` endpoint accepts the following query parameters:\n\n| Parameter        | Description                                                                                                                                                                      |\n| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `op`             | Operation names, separated by commas. Supported operations: `fit`, `smartcrop`, `pixelate`. Default: `fit`                                                                       |\n| `w`              | Width of the target image.                                                                                                                                                       |\n| `h`              | Height of the target image.                                                                                                                                                      |\n| `format`         | Output format. Supported values: `jpeg`, `png`, `gif`, `webp`, `auto`. Defaults to `Content-Type` of the requested image. Set `auto` to return WebP to browsers that support it. |\n| `strip`          | Strip metadata from the image. Supported values: `true`, `false`. Default: `true`                                                                                                |\n| `q`              | Quality of the output image. Supported values: `0-100`. Default: `80`                                                                                                            |\n| `pixelatefactor` | Pixelate factor, for example: `1-100`. The smaller the number, the less \"pixelized\" the result will be. Default: `20`                                                            |\n| `page`           | Page number, used for PDF previews and for GIF previews (the number of the frame to extract). Default: `1`                                                                       |\n| `s`              | Signature. Required when `MEDIATOR_SECRET_KEY` is set.                                                                                                                           |\n\n#### Operations\n\nCurrently, the following operations are supported:\n\n- **Fit**. Resize the image to fit within the specified dimensions, keeping the aspect ratio. The image will be downsized to the largest size that fits within the specified dimensions.\n- **Smartcrop**. Crop the image to the specified dimensions, using a smart algorithm to find the most interesting part of the image.\n- **Pixelate**. Pixelate the image. The `pixelatefactor` parameter controls the level of pixelation.\n\n### Renderers\n\nMediator can proxy requests to external services, like PDF/screenshot renderers and wrap the response in a signed, cacheable URL:\n\n```\n/render/:renderer/:payload?queryparam=1\u0026queryparam2=2\n```\n\nThe path params are:\n\n- `renderer`: the name of the renderer, as defined in the `MEDIATOR_RENDERERS` environment variable.\n- `payload`: base64-encoded (urlsafe) JSON with the following properties:\n  - `url`: target URL passed to the renderer (the URL you want to capture)\n  - `filename`: suggested filename, passed in the `Content-Disposition` header to the client\n\nExample payload:\n\n```bash\necho '{\n  \"url\": \"https://example.com/invoice/123456.html\",\n  \"filename\": \"VAT Invoice 123456.pdf\"\n}' | basenc --base64url\n# =\u003e ewogICJ1cmwiOiAiaHR0cHM6Ly9leGFtcGxlLmNvbS9pbnZvaWNlLzEyMzQ1Ni5odG1sIiwKICAiZmlsZW5hbWUiOiAiVkFUIEludm9pY2UgMTIzNDU2LnBkZiIKfQo=\n```\n\nQuery params are optional and will be passed to the renderer, not to the captured/target URL.\n\nExample URL:\n\n```\nhttp://localhost:8000/render/pdf/ewogICJ1cmwiOiAiaHR0cHM6Ly9leGFtcGxlLmNvbS9pbnZvaWNlLzEyMzQ1Ni5odG1sIiwKICAiZmlsZW5hbWUiOiAiVkFUIEludm9pY2UgMTIzNDU2LnBkZiIKfQo=\n```\n\n## URL Signing\n\nThe signing mechanism is based on the `MEDIATOR_SECRET_KEY` environment variable. When the key is set, the service will require a `s` parameter in the query string, containing the signature of the request.\n\nThe algorithm to generate the signature:\n\n```\npath_with_query_params = \"/image/transform/images-dev/2024/02/2431ckhy8z9s1tya4trk21pb3f.jpg?h=300\u0026w=300\"\nsignature = HMAC-SHA256(MEDIATOR_SECRET_KEY, path_with_query_params)\nsigned_url = path_with_query_params + \"\u0026s=\" + signature\n```\n\nSee also: [examples](https://github.com/pch/mediator/tree/main/examples)\n\n---\n\n## Configuration\n\nMediator can be configured using `ENV` variables:\n\n| Variable                     | Description                                                                                                                                                                                                                         | Default                    |\n| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- |\n| `MEDIATOR_SOURCES`           | Optional. List of supported sources to pull files from. JSON array of objects with `name` and `url` properties. Example:\u003cbr\u003e`[{ \"name\": \"mybucket\", \"url\": \"https://mybucket.s3.amazonaws.com\" }]`                                  |                            |\n| `MEDIATOR_RENDERERS`         | Optional. List of supported renderers (PDF, screenshot, etc.) to use. JSON array with `name` and `url` properties. Example:\u003cbr\u003e`[{ \"name\": \"pdf\", \"url\": \"https://pdf-renderer.example.com?url=%s\" }]`                              |                            |\n| `MEDIATOR_SECRET_KEY`        | Optional, but **highly encouraged**. Secret random key, used to generate URL signatures. Can be ganerated with:\u003cbr\u003e `dd if=/dev/urandom bs=32 count=1 2\u003e/dev/null \\| base64 \\| tr -d '='`                                           | `\"\"`                       |\n| `MEDIATOR_AUTH_TOKEN`        | Optional. Token for authenticating image requests (for `Authorization: Bearer \u003cAUTH_TOKEN\u003e`). You can set it when configuring your CDN to prevent direct access to the service.                                                     | `\"\"`                       |\n| `MEDIATOR_PATH_PREFIX`       | Optional. Prefix for the image processing URL paths. Useful when you have a CDN pulling from multiple sources. \u003cbr\u003eExample: `PATH_PREFIX=/my-prefix` will change the `transform` URL to `/my-prefix/image/transform/:source/:path`. | `\"\"`                       |\n| `MEDIATOR_CACHE_CONTROL`     | Value for the `Cache-Control` header.                                                                                                                                                                                               | `public, max-age=31536000` |\n| `MEDIATOR_DOWNLOAD_MAX_SIZE` | File size download limit, in bytes.                                                                                                                                                                                                 | `50MB`                     |\n| `MEDIATOR_DOWNLOAD_TIMEOUT`  | Download timeout, in seconds.                                                                                                                                                                                                       | `10s`                      |\n| `MEDIATOR_HTTP_PORT`         | HTTP port for the service.                                                                                                                                                                                                          | `8000`                     |\n| `MEDIATOR_LOG_LEVEL`         | Log level. Supported values: `debug`, `info`, `warn`, `error`.                                                                                                                                                                      | `info`                     |\n\n## Deployment\n\n### Deploying with Kamal\n\nExample configuration for [Kamal](https://kamal-deploy.org/), with Mediator running as an accessory:\n\n```yaml\nservice: example\nimage: pch/example # your main app\n\nservers:\n  web:\n    hosts:\n      - 123.123.123.123\n    labels:\n      traefik.http.routers.peeper.entrypoints: websecure\n      traefik.http.routers.peeper.rule: Host(`example.com`)\n      traefik.http.routers.peeper.tls.certresolver: letsencrypt\n\naccessories:\n  mediator:\n    image: ghcr.io/pch/mediator:latest\n    roles:\n      - web # will run on the same host as the main app\n    port: \"8000:8000\"\n    env:\n      clear:\n        MEDIATOR_SOURCES: '[{ \"name\": \"images-dev\", \"url\": \"https://example-dev.s3.amazonaws.com\" }, { \"name\": \"images\", \"url\": \"https://example-prod.s3.amazonaws.com\" }]'\n      secret:\n        - MEDIATOR_SECRET_KEY\n        - MEDIATOR_AUTH_TOKEN\n    labels:\n      traefik.http.routers.mediator.entrypoints: websecure\n      traefik.http.routers.mediator.rule: Host(`mediator.example.com`)\n      traefik.http.routers.mediator.tls.certresolver: letsencrypt\n      traefik.tcp.services.mediator.loadbalancer.server.port: 8000\n```\n\n### Deploying with Kubernetes\n\nExample configuration for a Kubernetes deployment:\n\n```yaml\napiVersion: v1\nkind: Service\nmetadata:\n  name: mediator\n  labels:\n    app: mediator\nspec:\n  ports:\n    - port: 80\n      targetPort: 8000\n  selector:\n    app: mediator\n---\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: mediator-deployment\nspec:\n  replicas: 1\n  selector:\n    matchLabels:\n      app: mediator\n  strategy:\n    type: RollingUpdate\n    rollingUpdate:\n      maxUnavailable: 0\n      maxSurge: 1\n  template:\n    metadata:\n      labels:\n        app: mediator\n    spec:\n      containers:\n        - name: mediator\n          image: ghcr.io/pch/mediator:latest\n          ports:\n            - containerPort: 8000\n          env:\n            - name: MEDIATOR_RENDERERS\n              value: '[{\"name\": \"pdf\", \"url\": \"http://url2pdf/api/render?goto.waitUntil=networkidle0\u0026scrollPage=true\u0026waitFor=500\u0026url=%s\"}]'\n            - name: MEDIATOR_LOG_LEVEL\n              value: debug\n            - name: MEDIATOR_SECRET_KEY\n              valueFrom:\n                secretKeyRef:\n                  name: mediator-secret\n                  key: secret_key\n          readinessProbe:\n            httpGet:\n              scheme: HTTP\n              path: /\n              port: 8000\n            initialDelaySeconds: 5\n```\n\nYou may also need to set up nginx ingress:\n\n```yaml\napiVersion: networking.k8s.io/v1\nkind: Ingress\nmetadata:\n  name: my-app-ingress-mediator\n  annotations:\n    kubernetes.io/ingress.class: \"nginx\"\n    cert-manager.io/cluster-issuer: \"letsencrypt-prod\"\nspec:\n  tls:\n    - hosts:\n        - mediator.example.com\n      secretName: my-app-tls\n  rules:\n    - host: mediator.example.com\n      http:\n        paths:\n          - path: /\n            pathType: Prefix\n            backend:\n              service:\n                name: mediator\n                port:\n                  number: 80\n```\n\n### CloudFront setup\n\nIf you decide to use CloudFront for CDN, there are only a few considerations to take into account:\n\n- When setting up an origin, make sure to set the `Authorization` header to `Bearer \u003cYOUR_AUTH_TOKEN\u003e` to prevent direct (non-cached) access to the service.\n- In the Behavior settings, you have to make sure that the query string is forwarded\n- In the \"Choose which headers to include in the cache key\" part, add the `Accept` header if you want to serve WebP images to browsers that support it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpch%2Fmediator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpch%2Fmediator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpch%2Fmediator/lists"}