mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-15 02:15:54 -07:00
feat: allow to remove ICC profile metadata
This commit is contained in:
parent
941b15cd9a
commit
5d322714ec
5 changed files with 30 additions and 2 deletions
|
|
@ -90,6 +90,7 @@ type Options struct {
|
||||||
Flip bool
|
Flip bool
|
||||||
Flop bool
|
Flop bool
|
||||||
NoAutoRotate bool
|
NoAutoRotate bool
|
||||||
|
NoProfile bool
|
||||||
Interlace bool
|
Interlace bool
|
||||||
Rotate Angle
|
Rotate Angle
|
||||||
Gravity Gravity
|
Gravity Gravity
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,7 @@ func Resize(buf []byte, o Options) ([]byte, error) {
|
||||||
Type: o.Type,
|
Type: o.Type,
|
||||||
Compression: o.Compression,
|
Compression: o.Compression,
|
||||||
Interlace: o.Interlace,
|
Interlace: o.Interlace,
|
||||||
|
NoProfile: o.NoProfile,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally save as buffer
|
// Finally save as buffer
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,21 @@ func TestInvalidRotate(t *testing.T) {
|
||||||
Write("fixtures/test_invalid_rotate_out.jpg", newImg)
|
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) {
|
func TestConvert(t *testing.T) {
|
||||||
width, height := 300, 240
|
width, height := 300, 240
|
||||||
formats := [3]ImageType{PNG, WEBP, JPEG}
|
formats := [3]ImageType{PNG, WEBP, JPEG}
|
||||||
|
|
|
||||||
8
vips.go
8
vips.go
|
|
@ -36,6 +36,7 @@ type vipsSaveOptions struct {
|
||||||
Compression int
|
Compression int
|
||||||
Type ImageType
|
Type ImageType
|
||||||
Interlace bool
|
Interlace bool
|
||||||
|
NoProfile bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type vipsWatermarkOptions struct {
|
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) {
|
func vipsSave(image *C.struct__VipsImage, o vipsSaveOptions) ([]byte, error) {
|
||||||
var ptr unsafe.Pointer
|
|
||||||
length := C.size_t(0)
|
length := C.size_t(0)
|
||||||
err := C.int(0)
|
err := C.int(0)
|
||||||
interlace := C.int(boolToInt(o.Interlace))
|
interlace := C.int(boolToInt(o.Interlace))
|
||||||
|
|
||||||
|
// Remove ICC profile metadata
|
||||||
|
if o.NoProfile {
|
||||||
|
C.remove_profile(image)
|
||||||
|
}
|
||||||
|
|
||||||
// Force RGB color space
|
// Force RGB color space
|
||||||
var outImage *C.struct__VipsImage
|
var outImage *C.struct__VipsImage
|
||||||
C.vips_colourspace_bridge(image, &outImage)
|
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(image))
|
||||||
defer C.g_object_unref(C.gpointer(outImage))
|
defer C.g_object_unref(C.gpointer(outImage))
|
||||||
|
|
||||||
|
var ptr unsafe.Pointer
|
||||||
switch o.Type {
|
switch o.Type {
|
||||||
case PNG:
|
case PNG:
|
||||||
err = C.vips_pngsave_bridge(outImage, &ptr, &length, 1, C.int(o.Compression), C.int(o.Quality), interlace)
|
err = C.vips_pngsave_bridge(outImage, &ptr, &length, 1, C.int(o.Compression), C.int(o.Quality), interlace)
|
||||||
|
|
|
||||||
7
vips.h
7
vips.h
|
|
@ -86,7 +86,12 @@ vips_exif_orientation(VipsImage *image) {
|
||||||
|
|
||||||
int
|
int
|
||||||
has_profile_embed(VipsImage *image) {
|
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
|
int
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue