From 0fa36db8130765a92d2c197f852a3438dd0ba669 Mon Sep 17 00:00:00 2001 From: DarthSim Date: Mon, 7 Jun 2021 15:05:29 +0600 Subject: [PATCH] Use magenta as a transparency key for trim --- CHANGELOG.md | 2 ++ docs/generating_the_url_advanced.md | 4 +++- vips.c | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91a682ac..c6baa976 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog ## [Unreleased] +### Change +- Use magenta (ff00ff) as a transparency key in `trim`. ## [2.16.3] - 2021-04-05 ### Fix diff --git a/docs/generating_the_url_advanced.md b/docs/generating_the_url_advanced.md index a2bf78ab..9979aece 100644 --- a/docs/generating_the_url_advanced.md +++ b/docs/generating_the_url_advanced.md @@ -207,7 +207,9 @@ Removes surrounding background. **⚠️Warning:** Trimming requires an image to be fully loaded into memory. This disables scale-on-load and significantly increases memory usage and processing time. Use it carefully with large images. -**📝Note:** If you know background color of your images then setting it explicitly via `color` will also save some resources because libvips won't detect it automatically. +**📝Note:** If you know background color of your images then setting it explicitly via `color` will also save some resources because imgproxy won't detect it automatically. + +**📝Note:** Use `color` value of `FF00FF` for trimming transparent background as imgproxy uses magenta as a transparency key. **📝Note:** Trimming of animated images is not supported. diff --git a/vips.c b/vips.c index 525c046d..910e6db7 100644 --- a/vips.c +++ b/vips.c @@ -470,7 +470,7 @@ vips_trim(VipsImage *in, VipsImage **out, double threshold, VipsImage *tmp; if (vips_image_hasalpha(in)) { - if (vips_flatten(in, &tmp, NULL)) + if (vips_flatten_go(in, &tmp, 255.0, 0, 255.0)) return 1; } else { if (vips_copy(in, &tmp, NULL))