瀏覽代碼

Strip watermark meta and remove its palette depth

DarthSim 2 年之前
父節點
當前提交
723666ea1a
共有 3 個文件被更改,包括 10 次插入0 次删除
  1. 1 0
      CHANGELOG.md
  2. 5 0
      processing/watermark.go
  3. 4 0
      vips/vips.go

+ 1 - 0
CHANGELOG.md

@@ -4,6 +4,7 @@
 ### Fix
 - Fix crashes in cases where the `max_bytes` processing option was used and image saving failed.
 - Fix error when using the `extend` or `extend_aspect_ratio` processing option while setting zero width or height.
+- Fix color loss when applying a watermark with a palette on an image without a palette.
 - (pro) Fix crashes when using `IMGPROXY_SMART_CROP_FACE_DETECTION` with large `IMGPROXY_CONCURRENCY`.
 - (pro) Fix watermark scaling when neither watermark scale nor watermark size is specified.
 

+ 5 - 0
processing/watermark.go

@@ -18,6 +18,7 @@ var watermarkPipeline = pipeline{
 	scale,
 	rotateAndFlip,
 	padding,
+	stripMetadata,
 }
 
 func prepareWatermark(wm *vips.Image, wmData *imagedata.ImageData, opts *options.WatermarkOptions, imgWidth, imgHeight int, offsetScale float64, framesCount int) error {
@@ -30,6 +31,8 @@ func prepareWatermark(wm *vips.Image, wmData *imagedata.ImageData, opts *options
 	po.Dpr = 1
 	po.Enlarge = true
 	po.Format = wmData.Type
+	po.StripMetadata = true
+	po.KeepCopyright = false
 
 	if opts.Scale > 0 {
 		po.Width = imath.Max(imath.ScaleToEven(imgWidth, opts.Scale), 1)
@@ -77,6 +80,8 @@ func prepareWatermark(wm *vips.Image, wmData *imagedata.ImageData, opts *options
 		}
 	}
 
+	wm.RemoveHeader("palette-bit-depth")
+
 	return nil
 }
 

+ 4 - 0
vips/vips.go

@@ -484,6 +484,10 @@ func (img *Image) SetBlob(name string, value []byte) {
 	C.vips_image_set_blob_copy(img.VipsImage, cachedCString(name), unsafe.Pointer(&value[0]), C.size_t(len(value)))
 }
 
+func (img *Image) RemoveHeader(name string) {
+	C.vips_image_remove(img.VipsImage, cachedCString(name))
+}
+
 func (img *Image) CastUchar() error {
 	var tmp *C.VipsImage