mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-10 20:22:31 +02:00
Fix trimming of CMYK images
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
## Add
|
### Add
|
||||||
- Add support of 16-bit BMP.
|
- Add support of 16-bit BMP.
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
- Fix trimming of CMYK images.
|
||||||
|
|
||||||
## [3.6.0] - 2022-06-13
|
## [3.6.0] - 2022-06-13
|
||||||
### Add
|
### Add
|
||||||
- Add `IMGPROXY_RETURN_ATTACHMENT` config and [return_attachment](https://docs.imgproxy.net/generating_the_url?return-attachment) processing option.
|
- Add `IMGPROXY_RETURN_ATTACHMENT` config and [return_attachment](https://docs.imgproxy.net/generating_the_url?return-attachment) processing option.
|
||||||
|
@@ -8,6 +8,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func importColorProfile(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, imgdata *imagedata.ImageData) error {
|
func importColorProfile(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, imgdata *imagedata.ImageData) error {
|
||||||
|
if pctx.iccImported {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if err := img.Rad2Float(); err != nil {
|
if err := img.Rad2Float(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,11 @@ func trim(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We need to import color profile before trim
|
||||||
|
if err := importColorProfile(pctx, img, po, imgdata); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if err := img.Trim(po.Trim.Threshold, po.Trim.Smart, po.Trim.Color, po.Trim.EqualHor, po.Trim.EqualVer); err != nil {
|
if err := img.Trim(po.Trim.Threshold, po.Trim.Smart, po.Trim.Color, po.Trim.EqualHor, po.Trim.EqualVer); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
43
vips/vips.c
43
vips/vips.c
@@ -380,37 +380,50 @@ int
|
|||||||
vips_trim(VipsImage *in, VipsImage **out, double threshold,
|
vips_trim(VipsImage *in, VipsImage **out, double threshold,
|
||||||
gboolean smart, double r, double g, double b,
|
gboolean smart, double r, double g, double b,
|
||||||
gboolean equal_hor, gboolean equal_ver) {
|
gboolean equal_hor, gboolean equal_ver) {
|
||||||
VipsImage *tmp;
|
|
||||||
|
|
||||||
if (vips_image_hasalpha(in)) {
|
VipsImage *base = vips_image_new();
|
||||||
if (vips_flatten_go(in, &tmp, 255.0, 0, 255.0))
|
VipsImage **t = (VipsImage **) vips_object_local_array(VIPS_OBJECT(base), 2);
|
||||||
return 1;
|
|
||||||
} else {
|
VipsImage *tmp = in;
|
||||||
if (vips_copy(in, &tmp, NULL))
|
|
||||||
|
if (vips_image_guess_interpretation(in) != VIPS_INTERPRETATION_sRGB) {
|
||||||
|
if (vips_colourspace(in, &t[0], VIPS_INTERPRETATION_sRGB, NULL)) {
|
||||||
|
clear_image(&base);
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
tmp = t[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
double *bg;
|
if (vips_image_hasalpha(tmp)) {
|
||||||
|
if (vips_flatten_go(tmp, &t[1], 255.0, 0, 255.0)) {
|
||||||
|
clear_image(&base);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
tmp = t[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
double *bg = NULL;
|
||||||
int bgn;
|
int bgn;
|
||||||
VipsArrayDouble *bga;
|
VipsArrayDouble *bga;
|
||||||
|
|
||||||
if (smart) {
|
if (smart) {
|
||||||
if (vips_getpoint(tmp, &bg, &bgn, 0, 0, NULL)) {
|
if (vips_getpoint(tmp, &bg, &bgn, 0, 0, NULL)) {
|
||||||
clear_image(&tmp);
|
clear_image(&base);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
bga = vips_array_double_new(bg, bgn);
|
bga = vips_array_double_new(bg, bgn);
|
||||||
} else {
|
} else {
|
||||||
bga = vips_array_double_newv(3, r, g, b);
|
bga = vips_array_double_newv(3, r, g, b);
|
||||||
bg = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int left, right, top, bot, width, height, diff;
|
int left, right, top, bot, width, height, diff;
|
||||||
|
int res = vips_find_trim(tmp, &left, &top, &width, &height, "background", bga, "threshold", threshold, NULL);
|
||||||
|
|
||||||
if (vips_find_trim(tmp, &left, &top, &width, &height, "background", bga, "threshold", threshold, NULL)) {
|
clear_image(&base);
|
||||||
clear_image(&tmp);
|
vips_area_unref((VipsArea *)bga);
|
||||||
vips_area_unref((VipsArea *)bga);
|
g_free(bg);
|
||||||
g_free(bg);
|
|
||||||
|
if (res) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -436,10 +449,6 @@ vips_trim(VipsImage *in, VipsImage **out, double threshold,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clear_image(&tmp);
|
|
||||||
vips_area_unref((VipsArea *)bga);
|
|
||||||
g_free(bg);
|
|
||||||
|
|
||||||
if (width == 0 || height == 0) {
|
if (width == 0 || height == 0) {
|
||||||
return vips_copy(in, out, NULL);
|
return vips_copy(in, out, NULL);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user