Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

im7: Return bytes for GetImageProfile #320

Merged
merged 1 commit into from
May 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't break the existing API. What if we rename this function to GetImageProfileBytes, and then make a GetImageProfile call GetImageProfileBytes and return a string?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback. I added a new function GetImageProfileBytes() and changed GetImageProfile() back to return a 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
Loading