feat: allow to remove ICC profile metadata

master
Tomas Aparicio 11 years ago
parent 941b15cd9a
commit 5d322714ec

@ -90,6 +90,7 @@ type Options struct {
Flip bool
Flop bool
NoAutoRotate bool
NoProfile bool
Interlace bool
Rotate Angle
Gravity Gravity

@ -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

@ -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}

@ -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)

@ -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

Loading…
Cancel
Save