Skip to content

Commit

Permalink
strip metadata if strip_exif
Browse files Browse the repository at this point in the history
TODO: add support for heif, jp2k
  • Loading branch information
liudongmiao authored and Liu Dongmiao committed Aug 27, 2024
1 parent 7a98a6f commit 3068623
Show file tree
Hide file tree
Showing 3 changed files with 24 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 @@ -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 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
19 changes: 17 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 @@ -592,30 +592,45 @@ func (v *Processor) export(
if compression > 0 {
opts.Compression = compression
}
if stripExif {
opts.StripMetadata = true
}
return image.ExportPng(opts)
case ImageTypeWEBP:
opts := NewWebpExportParams()
if quality > 0 {
opts.Quality = quality
}
if stripExif {
opts.StripMetadata = true
}
return image.ExportWebp(opts)
case ImageTypeTIFF:
opts := NewTiffExportParams()
if quality > 0 {
opts.Quality = quality
}
if stripExif {
opts.StripMetadata = true
}
return image.ExportTiff(opts)
case ImageTypeGIF:
opts := NewGifExportParams()
if quality > 0 {
opts.Quality = quality
}
if stripExif {
opts.StripMetadata = true
}
return image.ExportGIF(opts)
case ImageTypeAVIF:
opts := NewAvifExportParams()
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 3068623

Please sign in to comment.