Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strip metadata for webp and avif #469

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading