feat(#189): allow strip image metadata via bimg.Options.StripMetadata = bool

This commit is contained in:
Tomas Aparicio 2017-09-10 17:16:31 +02:00
parent d31288c3c8
commit ab4ef56bab
25 changed files with 12 additions and 8 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 198 KiB

After

Width:  |  Height:  |  Size: 198 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 199 KiB

After

Width:  |  Height:  |  Size: 199 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 199 KiB

After

Width:  |  Height:  |  Size: 200 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 198 KiB

After

Width:  |  Height:  |  Size: 199 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 204 KiB

After

Width:  |  Height:  |  Size: 205 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 204 KiB

After

Width:  |  Height:  |  Size: 205 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 203 KiB

After

Width:  |  Height:  |  Size: 204 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 204 KiB

After

Width:  |  Height:  |  Size: 205 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 KiB

After

Width:  |  Height:  |  Size: 165 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 165 KiB

After

Width:  |  Height:  |  Size: 166 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 165 KiB

After

Width:  |  Height:  |  Size: 166 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 165 KiB

After

Width:  |  Height:  |  Size: 165 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 173 KiB

After

Width:  |  Height:  |  Size: 174 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 174 KiB

After

Width:  |  Height:  |  Size: 174 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 173 KiB

After

Width:  |  Height:  |  Size: 173 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 174 KiB

After

Width:  |  Height:  |  Size: 174 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 111 KiB

After

Width:  |  Height:  |  Size: 111 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 64 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 116 KiB

After

Width:  |  Height:  |  Size: 117 KiB

Before After
Before After

View file

@ -204,6 +204,7 @@ type Options struct {
NoAutoRotate bool NoAutoRotate bool
NoProfile bool NoProfile bool
Interlace bool Interlace bool
StripMetadata bool
Extend Extend Extend Extend
Rotate Angle Rotate Angle
Background Color Background Color

View file

@ -161,6 +161,7 @@ func saveImage(image *C.VipsImage, o Options) ([]byte, error) {
NoProfile: o.NoProfile, NoProfile: o.NoProfile,
Interpretation: o.Interpretation, Interpretation: o.Interpretation,
OutputICC: o.OutputICC, OutputICC: o.OutputICC,
StripMetadata: o.StripMetadata,
} }
// Finally get the resultant buffer // Finally get the resultant buffer
return vipsSave(image, saveOptions) return vipsSave(image, saveOptions)

View file

@ -55,6 +55,7 @@ type vipsSaveOptions struct {
Type ImageType Type ImageType
Interlace bool Interlace bool
NoProfile bool NoProfile bool
StripMetadata bool
OutputICC string // Absolute path to the output ICC profile OutputICC string // Absolute path to the output ICC profile
Interpretation Interpretation Interpretation Interpretation
} }
@ -420,6 +421,7 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) {
saveErr := C.int(0) saveErr := C.int(0)
interlace := C.int(boolToInt(o.Interlace)) interlace := C.int(boolToInt(o.Interlace))
quality := C.int(o.Quality) quality := C.int(o.Quality)
strip := C.int(boolToInt(o.Interlace))
if o.Type != 0 && !IsTypeSupportedSave(o.Type) { if o.Type != 0 && !IsTypeSupportedSave(o.Type) {
return nil, fmt.Errorf("VIPS cannot save to %#v", ImageTypes[o.Type]) return nil, fmt.Errorf("VIPS cannot save to %#v", ImageTypes[o.Type])
@ -427,13 +429,13 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) {
var ptr unsafe.Pointer var ptr unsafe.Pointer
switch o.Type { switch o.Type {
case WEBP: case WEBP:
saveErr = C.vips_webpsave_bridge(tmpImage, &ptr, &length, 1, quality) saveErr = C.vips_webpsave_bridge(tmpImage, &ptr, &length, strip, quality)
case PNG: case PNG:
saveErr = C.vips_pngsave_bridge(tmpImage, &ptr, &length, 1, C.int(o.Compression), quality, interlace) saveErr = C.vips_pngsave_bridge(tmpImage, &ptr, &length, strip, C.int(o.Compression), quality, interlace)
case TIFF: case TIFF:
saveErr = C.vips_tiffsave_bridge(tmpImage, &ptr, &length) saveErr = C.vips_tiffsave_bridge(tmpImage, &ptr, &length)
default: default:
saveErr = C.vips_jpegsave_bridge(tmpImage, &ptr, &length, 1, quality, interlace) saveErr = C.vips_jpegsave_bridge(tmpImage, &ptr, &length, strip, quality, interlace)
} }
if int(saveErr) != 0 { if int(saveErr) != 0 {

8
vips.h
View file

@ -269,7 +269,7 @@ vips_icc_transform_bridge (VipsImage *in, VipsImage **out, const char *output_ic
int int
vips_jpegsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int quality, int interlace) { vips_jpegsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int quality, int interlace) {
return vips_jpegsave_buffer(in, buf, len, return vips_jpegsave_buffer(in, buf, len,
"strip", strip, "strip", strip == 1 ? TRUE : FALSE,
"Q", quality, "Q", quality,
"optimize_coding", TRUE, "optimize_coding", TRUE,
"interlace", with_interlace(interlace), "interlace", with_interlace(interlace),
@ -281,7 +281,7 @@ int
vips_pngsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int compression, int quality, int interlace) { vips_pngsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int compression, int quality, int interlace) {
#if (VIPS_MAJOR_VERSION >= 8 || (VIPS_MAJOR_VERSION >= 7 && VIPS_MINOR_VERSION >= 42)) #if (VIPS_MAJOR_VERSION >= 8 || (VIPS_MAJOR_VERSION >= 7 && VIPS_MINOR_VERSION >= 42))
return vips_pngsave_buffer(in, buf, len, return vips_pngsave_buffer(in, buf, len,
"strip", FALSE, "strip", strip == 1 ? TRUE : FALSE,
"compression", compression, "compression", compression,
"interlace", with_interlace(interlace), "interlace", with_interlace(interlace),
"filter", VIPS_FOREIGN_PNG_FILTER_NONE, "filter", VIPS_FOREIGN_PNG_FILTER_NONE,
@ -289,7 +289,7 @@ vips_pngsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int compr
); );
#else #else
return vips_pngsave_buffer(in, buf, len, return vips_pngsave_buffer(in, buf, len,
"strip", FALSE, "strip", strip == 1 ? TRUE : FALSE,
"compression", compression, "compression", compression,
"interlace", with_interlace(interlace), "interlace", with_interlace(interlace),
NULL NULL
@ -300,7 +300,7 @@ vips_pngsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int compr
int int
vips_webpsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int quality) { vips_webpsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int quality) {
return vips_webpsave_buffer(in, buf, len, return vips_webpsave_buffer(in, buf, len,
"strip", strip, "strip", strip == 1 ? TRUE : FALSE,
"Q", quality, "Q", quality,
NULL NULL
); );

View file

@ -33,7 +33,7 @@ func TestVipsSave(t *testing.T) {
for _, typ := range types { for _, typ := range types {
image, _, _ := vipsRead(readImage("test.jpg")) image, _, _ := vipsRead(readImage("test.jpg"))
options := vipsSaveOptions{Quality: 95, Type: typ} options := vipsSaveOptions{Quality: 95, Type: typ, StripMetadata: true}
buf, err := vipsSave(image, options) buf, err := vipsSave(image, options)
if err != nil { if err != nil {