diff --git a/options.go b/options.go index d7866b5..d29ec3a 100644 --- a/options.go +++ b/options.go @@ -90,6 +90,7 @@ type Options struct { Flip bool Flop bool NoAutoRotate bool + NoProfile bool Interlace bool Rotate Angle Gravity Gravity diff --git a/resize.go b/resize.go index 8916eac..30993b4 100644 --- a/resize.go +++ b/resize.go @@ -126,6 +126,7 @@ func Resize(buf []byte, o Options) ([]byte, error) { Type: o.Type, Compression: o.Compression, Interlace: o.Interlace, + NoProfile: o.NoProfile, } // Finally save as buffer diff --git a/resize_test.go b/resize_test.go index b2109db..1397d6d 100644 --- a/resize_test.go +++ b/resize_test.go @@ -71,6 +71,21 @@ func TestInvalidRotate(t *testing.T) { Write("fixtures/test_invalid_rotate_out.jpg", newImg) } +func TestNoColorProfile(t *testing.T) { + options := Options{Width: 800, Height: 600, NoColorProfile: true} + buf, _ := Read("fixtures/test.jpg") + + newImg, err := Resize(buf, options) + if err != nil { + t.Errorf("Resize(imgData, %#v) error: %#v", options, err) + } + + metadata, err := Metadata(newImg) + if metadata.Profile == true { + t.Fatal("Invalid profile data") + } +} + func TestConvert(t *testing.T) { width, height := 300, 240 formats := [3]ImageType{PNG, WEBP, JPEG} diff --git a/vips.go b/vips.go index 991936d..e190e9c 100644 --- a/vips.go +++ b/vips.go @@ -36,6 +36,7 @@ type vipsSaveOptions struct { Compression int Type ImageType Interlace bool + NoProfile bool } type vipsWatermarkOptions struct { @@ -221,11 +222,15 @@ func vipsRead(buf []byte) (*C.struct__VipsImage, ImageType, error) { } func vipsSave(image *C.struct__VipsImage, o vipsSaveOptions) ([]byte, error) { - var ptr unsafe.Pointer length := C.size_t(0) err := C.int(0) interlace := C.int(boolToInt(o.Interlace)) + // Remove ICC profile metadata + if o.NoProfile { + C.remove_profile(image) + } + // Force RGB color space var outImage *C.struct__VipsImage C.vips_colourspace_bridge(image, &outImage) @@ -233,6 +238,7 @@ func vipsSave(image *C.struct__VipsImage, o vipsSaveOptions) ([]byte, error) { defer C.g_object_unref(C.gpointer(image)) defer C.g_object_unref(C.gpointer(outImage)) + var ptr unsafe.Pointer switch o.Type { case PNG: err = C.vips_pngsave_bridge(outImage, &ptr, &length, 1, C.int(o.Compression), C.int(o.Quality), interlace) diff --git a/vips.h b/vips.h index 9dbecdb..e380b1e 100644 --- a/vips.h +++ b/vips.h @@ -86,7 +86,12 @@ vips_exif_orientation(VipsImage *image) { int has_profile_embed(VipsImage *image) { - return (vips_image_get_typeof(image, VIPS_META_ICC_NAME) > 0) ? 1 : 0; + return vips_image_get_typeof(image, VIPS_META_ICC_NAME); +}; + +void +remove_profile(VipsImage *image) { + vips_image_remove(image, VIPS_META_ICC_NAME); }; int