Skip to content

Commit

Permalink
im7: Add func GetImageProfileBytes (#320)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
coderkun authored May 31, 2024
1 parent 6922a51 commit 76b9205
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions imagick/magick_wand_prop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 76b9205

Please sign in to comment.