Assign ICC profile to image

Started by humbleweed, November 20, 2013, 03:42:21 AM

Previous topic - Next topic

humbleweed

Dear all,

I'm trying to assign an ICC profile to an image / an exiftool object by

$et->SetNewGroups('ICC_Profile');
$et->SetNewValue('ICC_Profile' => $icc);

where $icc is a blob or a file. Both throws an error like "Tag 'ICC_Profile' is unsafe for writing".
I whould like to avoid assigning the profile by Image::Magick (which works).

Added recent: Adding Protected => 1 doesn't help; throws error "Error opening file" wether $icc is a file, filehandle or blob.

Phil Harvey

You don't need to call SetNewGroups().

The SetNewValue() call expects the ICC profile data.  If you have a file name, read it into a buffer (ie. $buff), and pass $buff to SetNewValue().  Alternatively, call $et->SetNewValuesFromFile($file, 'ICC_Profile');

You do need to set Protected => 1 for this as you discovered.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

humbleweed

Thank you Phil.

Yes, I tried to read the profile file to a scalar buffer with
   open ICCFH, '<', $iccFile};
   undef $/;
   $icc = <ICCFH>; # get blob
   close ICCFH;
   $/ = "\n";
and used it with IMagick - and it worked: $newimg->Profile(name => 'ICC', profile => $icc);

But with ExifTool: SetNewValue( $icc ) fails of course (new value for what?),
also SetNewValue( $icc, 'ICC_Profile' ) fails (Tags ???? - $icc is no Tag)
also SetNewValue( 'ICC_Profile', $icc ) fails (my first attempt and the way other things are working).

- Ludwig

Phil Harvey

Hi Ludwig,

You seem to be trying things randomly.  If $icc contains the profile data, then the call is:

    $et->SetNewValue('ICC_Profile', $icc, Protected => 1);

And to be clear, after this you must of course call

    $et->WriteInfo($outfile);

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

humbleweed

Hi Phil,

as I reported / added in my first post, I first tried it exact as you say:

  $et->SetNewValue('ICC_Profile' => $icc, Protected => 1);

and I got:
Writing ICC_Profile:ICC_Profile if tag exists (from: $et->Options(Verbose => 3); ) and then
    Error = Error opening file (from STDERR)

I also tried to use a file handle or path to the file.

- Ludwig

Phil Harvey

Hi Ludwig,

I'm sorry, but I don't understand.

Quote from: humbleweed on November 20, 2013, 10:24:43 AM
as I reported / added in my first post, I first tried it exact as you say:

  $et->SetNewValue('ICC_Profile' => $icc, Protected => 1);

and I got:
Writing ICC_Profile:ICC_Profile if tag exists (from: $et->Options(Verbose => 3); ) and then
    Error = Error opening file (from STDERR)

What file was it trying to open?  That command should not open a file if $icc contains the profile data in memory.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).