From e7dc1691c2be112756a02ccdb37842cf10eecd5a Mon Sep 17 00:00:00 2001 From: Oliver Hanraths Date: Thu, 30 May 2024 13:43:10 +0200 Subject: [PATCH] im7: Add func GetImageProfileBytes The C.MagickGetImageProfile() function returns a char array but it is not only the name of the profile but the bytes of the actual ICC profile. Add the function GetImageProfileBytes() to return []byte the same way RemoveImageProfile() does it. Keep the existing function GetImageProfile() to return a string to not break the existing API but adjust it to call GetImageProfileBytes() internally. --- imagick/magick_wand_prop.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/imagick/magick_wand_prop.go b/imagick/magick_wand_prop.go index 3ddcc23..bb119ca 100644 --- a/imagick/magick_wand_prop.go +++ b/imagick/magick_wand_prop.go @@ -133,13 +133,20 @@ func (mw *MagickWand) GetImageArtifacts(pattern string) (artifacts []string) { // // name: Name of profile to return: ICC, IPTC, or generic profile. func (mw *MagickWand) GetImageProfile(name string) string { + return string(mw.GetImageProfileBytes(name)) +} + +// GetImageProfileBytes returns the named image profile. +// +// name: Name of profile to return: ICC, IPTC, or generic profile. +func (mw *MagickWand) GetImageProfileBytes(name string) []byte { csname := C.CString(name) defer C.free(unsafe.Pointer(csname)) - szlen := C.size_t(0) - csprofile := C.MagickGetImageProfile(mw.mw, csname, &szlen) + clen := C.size_t(0) + profile := C.MagickGetImageProfile(mw.mw, csname, &clen) runtime.KeepAlive(mw) - defer relinquishMemory(unsafe.Pointer(csprofile)) - return C.GoStringN((*C.char)((unsafe.Pointer)(csprofile)), C.int(szlen)) + defer relinquishMemory(unsafe.Pointer(profile)) + return C.GoBytes(unsafe.Pointer(profile), C.int(clen)) } // GetImageProfiles Returns all the profile names that match the specified pattern associated