Page 1 of 1

Custom Properties (Attributes)

Posted: 2017-06-18T18:17:10-07:00
by ggarra13
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?

Re: Custom Properties (Attributes)

Posted: 2017-06-18T18:24:52-07:00
by fmw42
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.

Re: Custom Properties (Attributes)

Posted: 2017-06-18T19:14:05-07:00
by snibgo
MagickSetImageProperty() works fine for me. I suggest you post a complete but minimal program that shows the problem.

Re: Custom Properties (Attributes)

Posted: 2017-06-19T05:02:09-07:00
by ggarra13
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.

Re: Custom Properties (Attributes)

Posted: 2017-06-19T05:29:07-07:00
by snibgo
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?

Re: Custom Properties (Attributes)

Posted: 2017-06-19T05:35:41-07:00
by ggarra13
With PNG and MIFF, the attributes are saved properly. It seems a bug with the jpeg/dpx/tiff savers.

Re: Custom Properties (Attributes)

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

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;
}

Re: Custom Properties (Attributes)

Posted: 2017-06-19T06:17:55-07:00
by magick
You have 'dpx::'. It should be 'dpx:', only one colon.

Re: Custom Properties (Attributes)

Posted: 2017-06-19T13:46:05-07:00
by ggarra13
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.

Re: Custom Properties (Attributes)

Posted: 2017-06-19T15:03:30-07:00
by magick
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.