Custom Properties (Attributes)
Custom Properties (Attributes)
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?
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?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Custom Properties (Attributes)
You can write to the "comment" or "label" fields with your information. In command line mode:
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.
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:
see
http://www.imagemagick.org/script/comma ... hp#comment
http://www.imagemagick.org/script/comma ... .php#label
Sorry, I do not use an API.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Custom Properties (Attributes)
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
Re: Custom Properties (Attributes)
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.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Custom Properties (Attributes)
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?
As you are using CPP, why not use the attribute() method?
snibgo's IM pages: im.snibgo.com
Re: Custom Properties (Attributes)
With PNG and MIFF, the attributes are saved properly. It seems a bug with the jpeg/dpx/tiff savers.
Re: Custom Properties (Attributes)
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)
You have 'dpx::'. It should be 'dpx:', only one colon.
Re: Custom Properties (Attributes)
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)
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.