Skip to content

Commit

Permalink
strip metadata for webp and avif
Browse files Browse the repository at this point in the history
webp and avif is mainly for browser, it's safe to strip metadata.
  • Loading branch information
liudongmiao committed Aug 19, 2024
1 parent a510db8 commit b42e209
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
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
1 change: 1 addition & 0 deletions vips/foreign.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ func vipsSaveAVIFToBuffer(in *C.VipsImage, params AvifExportParams) ([]byte, err
p := C.create_save_params(C.AVIF)
p.inputImage = in
p.outputFormat = C.AVIF
p.stripMetadata = C.int(boolToInt(params.StripMetadata))
p.quality = C.int(params.Quality)
p.heifLossless = C.int(boolToInt(params.Lossless))
p.avifSpeed = C.int(params.Speed)
Expand Down
2 changes: 2 additions & 0 deletions vips/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ func (v *Processor) export(
return image.ExportPng(opts)
case ImageTypeWEBP:
opts := NewWebpExportParams()
opts.StripMetadata = true
if quality > 0 {
opts.Quality = quality
}
Expand All @@ -613,6 +614,7 @@ func (v *Processor) export(
return image.ExportGIF(opts)
case ImageTypeAVIF:
opts := NewAvifExportParams()
opts.StripMetadata = true
if quality > 0 {
opts.Quality = quality
}
Expand Down

0 comments on commit b42e209

Please sign in to comment.