Page 1 of 1

Implementing a user-specified image property

Posted: 2008-10-26T15:24:02-07:00
by rmagick
I'm thinking about supporting a way for an RMagick user to specify an arbitrary string property to be assigned to an image immediately after the image is read or otherwise created. What I'm going for is a way to easily identify a specific image for debugging purposes. (You could, for example, assign the filename and current line number of the Ruby script.) Because of the way RMagick works, the property would have to be initially assigned to the ImageInfo structure and then propagated to the Image.

I'm thinking I could add the property - let's name it the "user" property - to the ImageInfo structure with SetImageOption. Immediately after AcquireImage/ReadImage/whatever returns, if the "user" property exists, then I'd copy it to the Image structure via SetImageArtifact.

Is this an appropriate use of the Core API? Is there a better way?

Re: Implementing a user-specified image property

Posted: 2008-10-26T15:42:22-07:00
by magick
ImageMagick supports four types of properties: global properties, image options, image properties, and image artifacts. Global properties are stored / retrieved from the registry. Image options, associated with the ImageInfo structure, become image artifacts when an image is instantiated (Image structure) so your proposal to use this mechanism within RMagick is sound. The difference between image properties and image artifacts is that properties are public and artifacts are private. Private, here simply means the key/value pair is used internally whereas properties might end up in the image format when its written to disk.

Re: Implementing a user-specified image property

Posted: 2008-10-26T17:07:56-07:00
by rmagick
Thanks for the info. I was wondering about the difference between artifacts and properties. It was very simple to add this code to RMagick.