Custom Properties (Attributes)

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
ggarra13
Posts: 26
Joined: 2015-04-17T14:08:07-07:00
Authentication code: 6789

Custom Properties (Attributes)

Post by ggarra13 » 2017-06-18T18:17:10-07:00

I would like to save custom attributes (properties) in a psd, miff, tiff, jpg, etc. For example, key "writer", value "my name". This is using C++, with ImageMagick 7.0.4-9 Q32 x86_64 2017-02-16.
I am using MagickSetImageProperty, like:

std::string key = "writer";
std::string value = "my name";

MagickBooleanType status = MagickSetImageProperty( wand, key.c_str(), value.c_str() );
if ( status != MagickTrue )
{
std::cerr << "Error setting property " << key << " to " << value << std::endl;
}

This does not return an error, but the property does not get saved. I also tried the key begin with "exif:" or "iptc:" with no results.
What am I doing wrong?

User avatar
fmw42
Posts: 21505
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Custom Properties (Attributes)

Post by fmw42 » 2017-06-18T18:24:52-07:00

You can write to the "comment" or "label" fields with your information. In command line mode:

Code: Select all

convert logo: logo.jpg
convert logo.jpg  -set comment "this is my comment" logo.jpg
convert logo.jpg -format "%c\n" info:
this is my comment

see
http://www.imagemagick.org/script/comma ... hp#comment
http://www.imagemagick.org/script/comma ... .php#label

Sorry, I do not use an API.

snibgo
Posts: 9025
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Custom Properties (Attributes)

Post by snibgo » 2017-06-18T19:14:05-07:00

MagickSetImageProperty() works fine for me. I suggest you post a complete but minimal program that shows the problem.
snibgo's IM pages: im.snibgo.com

ggarra13
Posts: 26
Joined: 2015-04-17T14:08:07-07:00
Authentication code: 6789

Re: Custom Properties (Attributes)

Post by ggarra13 » 2017-06-19T05:02:09-07:00

I can set the value of, for example, "dpx::television.frame_rate" in a dpx file with MagickSetImageProperty. However, I seem not to be able to create a new attribute that is unknown to the saver. Or at least, it does not show up with: identify -verbose image.dpx.

snibgo
Posts: 9025
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Custom Properties (Attributes)

Post by snibgo » 2017-06-19T05:29:07-07:00

I don't know if attributes are saved in DPX files. Test your code with a PNG output.

As you are using CPP, why not use the attribute() method?
snibgo's IM pages: im.snibgo.com

ggarra13
Posts: 26
Joined: 2015-04-17T14:08:07-07:00
Authentication code: 6789

Re: Custom Properties (Attributes)

Post by ggarra13 » 2017-06-19T05:35:41-07:00

With PNG and MIFF, the attributes are saved properly. It seems a bug with the jpeg/dpx/tiff savers.

ggarra13
Posts: 26
Joined: 2015-04-17T14:08:07-07:00
Authentication code: 6789

Re: Custom Properties (Attributes)

Post by ggarra13 » 2017-06-19T05:39:56-07:00

Code: Select all

#include <iostream>
using namespace std;

#include <cstdio>
#include <MagickWand/MagickWand.h>


/*! ImageMagick does not allow testing a block of data,
  but allows testing a file or FILE*.
*/
bool test(const char* infile, const char* outfile )
{
    MagickWandGenesis();
    MagickBooleanType status = MagickFalse;

    MagickWand* wand = NewMagickWand(); 
    status = MagickReadImage( wand, infile );
    if (status == MagickFalse )
    {
        return false;
    }

    MagickSetImageProperty( wand, "dpx:film.frame_rate", "2" );  // this works
    MagickSetImageProperty( wand, "myattr", "full" );         // this does not

    status = MagickWriteImages( wand, outfile, MagickTrue );
    if (status == MagickFalse )
    {
        return false;
    }

    DestroyMagickWand(wand);


    MagickWandTerminus();

    if (status == MagickFalse )
    {
        return false;
    }

    return true;
}

int main( const int argc, const char* argv[] )
{
    if ( argc != 3 ) {
        std::cerr << argv[0] << std::endl << std::endl
                  << "Usage: " << std::endl << std::endl
                  << argv[0] << " inputfile outputfile " << std::endl;
        return -1;
    }

    bool ok = test( argv[1], argv[2] );
    if ( ok )
        std::cout << "Image write okay" << std::endl;
    else
        std::cerr << "Image write bad" << std::endl;
}

User avatar
magick
Site Admin
Posts: 10620
Joined: 2003-05-31T11:32:55-07:00

Re: Custom Properties (Attributes)

Post by magick » 2017-06-19T06:17:55-07:00

You have 'dpx::'. It should be 'dpx:', only one colon.

ggarra13
Posts: 26
Joined: 2015-04-17T14:08:07-07:00
Authentication code: 6789

Re: Custom Properties (Attributes)

Post by ggarra13 » 2017-06-19T13:46:05-07:00

I have "dpx:". And that attribute works. What does not work is custom attributes like "myattr" later. It works in MIFF and PNG. But it does not work with cin, dpx, jpg, psd, etc.

User avatar
magick
Site Admin
Posts: 10620
Joined: 2003-05-31T11:32:55-07:00

Re: Custom Properties (Attributes)

Post by magick » 2017-06-19T15:03:30-07:00

Custom attributes must be supported by a particular image format and by the image coder. If you can point us to a reference that shows custom attributes for the DPX image format, for example, are supported by the format specification, we will consider supporting custom attributes in a future release of ImageMagick. DPX does permit a user-data field but apparently that's for a custom image profile. The only fields currently supported for DPX, are discussed @ https://www.imagemagick.org/script/motion-picture.php.

Post Reply