From 492472ee85e2771e653fa3b8d8a113223188e6ca Mon Sep 17 00:00:00 2001 From: Liu Dongmiao Date: Mon, 19 Aug 2024 16:52:16 +0800 Subject: [PATCH] strip metadata if `strip_exif` for webp and avif TODO: add support for other format --- vips/foreign.c | 6 +++++- vips/foreign.go | 2 ++ vips/process.go | 10 ++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/vips/foreign.c b/vips/foreign.c index 4ab16eb42..bccd0521b 100644 --- a/vips/foreign.c +++ b/vips/foreign.c @@ -159,7 +159,11 @@ int set_gifsave_options(VipsOperation *operation, SaveParams *params) { int set_avifsave_options(VipsOperation *operation, SaveParams *params) { int ret = vips_object_set( VIPS_OBJECT(operation), "compression", VIPS_FOREIGN_HEIF_COMPRESSION_AV1, - "lossless", params->heifLossless, "speed", params->avifSpeed, NULL); + "lossless", params->heifLossless, + "effort", 9 - params->avifSpeed, // speed is deprecated + "strip", params->stripMetadata, + "subsample_mode", VIPS_FOREIGN_SUBSAMPLE_AUTO, // set to auto as we always set lossless + NULL); if (!ret && params->quality) { ret = vips_object_set(VIPS_OBJECT(operation), "Q", params->quality, NULL); diff --git a/vips/foreign.go b/vips/foreign.go index 7ad20e20a..b245f4ccb 100644 --- a/vips/foreign.go +++ b/vips/foreign.go @@ -231,6 +231,7 @@ func vipsSaveAVIFToBuffer(in *C.VipsImage, params AvifExportParams) ([]byte, err p.inputImage = in p.outputFormat = C.AVIF p.quality = C.int(params.Quality) + p.stripMetadata = C.int(boolToInt(params.StripMetadata)) p.heifLossless = C.int(boolToInt(params.Lossless)) p.avifSpeed = C.int(params.Speed) @@ -254,6 +255,7 @@ func vipsSaveGIFToBuffer(in *C.VipsImage, params GifExportParams) ([]byte, error p := C.create_save_params(C.GIF) p.inputImage = in p.quality = C.int(params.Quality) + p.stripMetadata = C.int(boolToInt(params.StripMetadata)) p.gifDither = C.double(params.Dither) p.gifEffort = C.int(params.Effort) p.gifBitdepth = C.int(params.Bitdepth) diff --git a/vips/process.go b/vips/process.go index 3775a6907..eb8b0dfb1 100644 --- a/vips/process.go +++ b/vips/process.go @@ -313,7 +313,7 @@ func (v *Processor) Process( } format = supportedSaveFormat(format) // convert to supported export format for { - buf, err := v.export(img, format, compression, quality, palette, bitdepth) + buf, err := v.export(img, format, compression, quality, palette, bitdepth, stripExif) if err != nil { return nil, WrapErr(err) } @@ -575,7 +575,7 @@ func supportedSaveFormat(format ImageType) ImageType { } func (v *Processor) export( - image *Image, format ImageType, compression int, quality int, palette bool, bitdepth int, + image *Image, format ImageType, compression int, quality int, palette bool, bitdepth int, stripExif bool, ) ([]byte, error) { switch format { case ImageTypePNG: @@ -598,6 +598,9 @@ func (v *Processor) export( if quality > 0 { opts.Quality = quality } + if stripExif { + opts.StripMetadata = true + } return image.ExportWebp(opts) case ImageTypeTIFF: opts := NewTiffExportParams() @@ -616,6 +619,9 @@ func (v *Processor) export( if quality > 0 { opts.Quality = quality } + if stripExif { + opts.StripMetadata = true + } opts.Speed = v.AvifSpeed return image.ExportAvif(opts) case ImageTypeHEIF: