Skip to content

Commit

Permalink
strip metadata if strip_exif for webp and avif (#469)
Browse files Browse the repository at this point in the history
TODO: add support for other format
  • Loading branch information
liudongmiao authored Aug 28, 2024
1 parent 7a98a6f commit d11d821
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion vips/foreign.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions vips/foreign.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions vips/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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:
Expand All @@ -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()
Expand All @@ -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:
Expand Down

0 comments on commit d11d821

Please sign in to comment.