Page 1 of 1

unable to read/write image metadata using jmagick from java code

Posted: 2016-11-30T04:00:41-07:00
by Vijay
Hi,
I am trying to update an image's metadata through the 'jmagick'(verstion 6.7.7) library in java. The function I used was 'setImageAttribute()'. Please see the pseudocode further down.

To upate metadata tag names, I referred the following link -
https://www.imagemagick.org/script/escape.php

This method updates the image's attributes, but the updated information is not persisting in the destination file. After the update, if I try reading the newly saved destination image(destFile.jpg) metadata, it still refers to the old data.

Am I missing some thing?
Does jmagick not supports reading/updating/writing image metadata?

Appreciate your quick help.

Thanks,
vijay.

Used psudo code -
{
MultippartFile image = "c:\temp\sample.jpg";
String srcFileName = "c:\\temp\tempFile";
String destFileName = "c:\\temp\destFile.jpg";
File srcFile = Utils.writeFile(image.getInputStream(), srcFileName);
ImageInfo imgInfo = new ImageInfo(srcFileName);
destImage = new MagickImage(imgInfo);

System.out.println("Before:");
System.out.println("Image comment value is = " + destImage.getImageAttribute("Comment"));
System.out.println("Image credit tag value is = " + destImage.getImageAttribute("2:110:Credit"));
System.out.println("Image copyright notice tag value is = " + destImage.getImageAttribute("2#116#Copyright Notice"));
System.out.println("Image contact tag value is = " + destImage.getImageAttribute("2#118#Contact"));

destImage.setImageAttribute("Comment", "It is copyrighted image");
destImage.setImageAttribute("2:110:Credit", "Mr. XYZ");
destImage.setImageAttribute("2#116#Copyright Notice", "copy right notice");
destImage.setImageAttribute("2#118#Contact", "XYZ");

destImage.setFileName(destFileName);
destImage.writeImage(imageInfo);


System.out.println("After writeImage call:");
System.out.println("Image comment value is = " + destImage.getImageAttribute("Comment"));
System.out.println("Image credit tag value is = " + destImage.getImageAttribute("2:110:Credit"));
System.out.println("Image copyright notice tag value is = " + destImage.getImageAttribute("2#116#Copyright Notice"));
System.out.println("Image contact tag value is = " + destImage.getImageAttribute("2#118#Contact"));
}

O/P from debug statements:
Before:
Image comment value is = null
Image credit tag value is = null
Image copyright notice tag value is = null
Image contact tag value is = = null

After writeImage call:
Image comment value is = It is copyrighted image
Image credit tag value is = Mr. XYZ
Image copyright notice tag value is = copy right notice
Image contact tag value is = = XYZ