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: 30
Joined: 2015-04-17T14:08:07-07:00
Authentication code: 6789

Custom Properties (Attributes)

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Custom Properties (Attributes)

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Custom Properties (Attributes)

Post by snibgo »

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: 30
Joined: 2015-04-17T14:08:07-07:00
Authentication code: 6789

Re: Custom Properties (Attributes)

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Custom Properties (Attributes)

Post 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?
snibgo's IM pages: im.snibgo.com
ggarra13
Posts: 30
Joined: 2015-04-17T14:08:07-07:00
Authentication code: 6789

Re: Custom Properties (Attributes)

Post by ggarra13 »

With PNG and MIFF, the attributes are saved properly. It seems a bug with the jpeg/dpx/tiff savers.
ggarra13
Posts: 30
Joined: 2015-04-17T14:08:07-07:00
Authentication code: 6789

Re: Custom Properties (Attributes)

Post 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;
}
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Custom Properties (Attributes)

Post by magick »

You have 'dpx::'. It should be 'dpx:', only one colon.
ggarra13
Posts: 30
Joined: 2015-04-17T14:08:07-07:00
Authentication code: 6789

Re: Custom Properties (Attributes)

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Custom Properties (Attributes)

Post 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.
Post Reply