Page 1 of 1
Get image property
Posted: 2009-02-08T20:17:20-07:00
by wchang615
Dear All,
I'm looking for a method to get the full list of image property similar to the command-line "identify -verbose". It seems to me the GetImageProperty only returns a single property based on a given key.
Also, are there any methods I could use to detect "Corrupt JPEG data" like the following:
Version: ImageMagick 6.4.8-4 2009-01-08 Q16 OpenMP
http://www.imagemagick.org
identify: Corrupt JPEG data: 1 extraneous bytes before marker 0xd9 `e:\pict_mpeg
\Pict_65_Trondheim_Jul_03\pictures\Picture_MPEG_Meeting_Trondheim_015.jpx' @ jpe
g.c/EmitMessage/227.
Thanks for any helps.
Best,
--Wo
Re: Get image property
Posted: 2009-02-09T07:22:24-07:00
by magick
To get all the properties of an image use code similar to what we use in IdentifyImage():
Code: Select all
(void) GetImageProperty(image,"exif:*");
ResetImagePropertyIterator(image);
property=GetNextImageProperty(image);
if (property != (const char *) NULL)
{
/*
Display image properties.
*/
(void) fprintf(file," Properties:\n");
while (property != (const char *) NULL)
{
(void) fprintf(file," %c",*property);
if (strlen(property) > 1)
(void) fprintf(file,"%s: ",property+1);
if (strlen(property) > 80)
(void) fputc('\n',file);
value=GetImageProperty(image,property);
if (value != (const char *) NULL)
(void) fprintf(file,"%s\n",value);
property=GetNextImageProperty(image);
}
}
To detect corrupt images you would need to write your own exception handling methods and intercept the messages as they are thrown.
Re: Get image property
Posted: 2009-02-09T08:10:28-07:00
by wchang615
Great and thanks for the sample code!
Not sure what I did wrong from my testing code (see below).
Problems with my code:
1. if I use "if (exp_info->severity == UndefinedException)"
it will always return 1. But then, for the CorruptImageError,
somehow it does not catch any corrupted image....
2. for some reasons, I'm not releasing allocated memory
which causing some files been written into
"....\Locat Setttings\Temp with the file names starting
with "Magick.....".
Any hints?
--Wo
Code: Select all
private: int Convert (String^ in, String^ out)
{
using namespace Magick;
using namespace MagickCore;
MagickCoreGenesis(".",MagickTrue);
std::string ifile = " ", ofile = " ";
ifile = MySysStrToStdStr (in);
ofile = MySysStrToStdStr (out);
MagickCore::Image *image;
MagickCore::Image **converted_image;
MagickCore::Image *scaled_image;
MagickCore::ImageInfo image_info;
MagickCore::ExceptionInfo *exp_info;
try
{
GetImageInfo(&image_info);
exp_info=AcquireExceptionInfo();
(void) strcpy(image_info.filename,&ifile[0]);
image=MagickCore::ReadImage(&image_info, exp_info);
//if (exp_info->severity == UndefinedException)
if (exp_info->severity == CorruptImageError)
{
MagickCore::DestroyImage(image);
return 1;
}
}
catch (MagickCore::ExceptionInfo *error_)
{
if (image != (MagickCore::Image *) NULL)
MagickCore::DestroyImage(image);
return 2;
}
converted_image = ℑ
try
{
if (image == (MagickCore::Image *) NULL)
{
return 3;
}
MagickCore::TransformImage(converted_image,"","256x256");
if (scaled_image != (MagickCore::Image *) NULL)
{
MagickCore::DestroyImage(image);
image=scaled_image;
}
// Write the image and destroy it.
(void) strcpy(image->filename,&ofile[0]);
MagickCore::WriteImage(&image_info,image);
}
catch (MagickCore::ExceptionInfo *error_)
{
if (image != (MagickCore::Image *) NULL)
MagickCore::DestroyImage(image);
return 4;
}
if (image != (MagickCore::Image *) NULL)
MagickCore::DestroyImage(image);
if (scaled_image != (MagickCore::Image *) NULL)
MagickCore::DestroyImage(scaled_image);
MagickCore::DestroyImageInfo(&image_info);
MagickCoreTerminus();
return 0;
}
Re: Get image property
Posted: 2009-02-09T08:20:00-07:00
by magick
You probably want CorruptImageWarning. Warning are exceptions that are recoverable where errors are corruptions that may prevent ImageMagick from continuing.
The magick-* temporary files are common and are used by ImageMagick for temporary disk storage. They should be removed automatically unless the program fails abruptly or if you control-c out of your program. You can simply delete these files or if you can produce a short code segment that completes and leaves magick-* temporary files behind we would want investigate further to ensure there is not a file leak.
Re: Get image property
Posted: 2009-02-09T08:28:58-07:00
by wchang615
BTW: how do you get *all* the general property info other than the "exif"?
Again, thanks for all your helps!
--Wo
Re: Get image property
Posted: 2009-02-09T08:37:50-07:00
by magick
The posted code gets you all of the the properties. The EXIF call breaks down the EXIF profile into individual properties. The other properties are already available.
Re: Get image property
Posted: 2009-02-09T21:21:20-07:00
by wchang615
Can I get beyound the Propertieis?
Like the "identify..." below.
Thanks.
--Wo
.....
exif:WhiteBalance: 0
exif:XResolution: 72/1
exif:YCbCrPositioning: 2
exif:YResolution: 72/1
jpeg:colorspace: 2
jpeg:sampling-factor: 2x1,1x1,1x1
modify-date: 2006-07-30T01:27:17+00:00
signature: 12a1de059867d4125eb279626a6afacb4c61f0c2fbf67b372e965848b7eddadc
Profiles:
Profile-exif: 14403 bytes
Artifacts:
verbose: true
Tainted: False
Filesize: 1.844mb
Number pixels: 7.62mb
Pixels per second: 25.32mb
User time: 0.300u
Elapsed time: 0:01
Version: ImageMagick 6.4.8-4 2009-01-08 Q16 OpenMP
http://www.imagemagick.org
identify: Corrupt JPEG data: premature end of data segment `ff.jpg' @ jpeg.c/Emi
tMessage/227.
identify: Unsupported marker type 0x50 `ff.jpg' @ jpeg.c/EmitMessage/232.