From 76b920571f21d5a981685ae8dd893548516e0a77 Mon Sep 17 00:00:00 2001 From: Olli Date: Fri, 31 May 2024 09:36:24 +0200 Subject: [PATCH] im7: Add func GetImageProfileBytes (#320) 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