Most digital cameras nowadays embed various pieces of information into the JPEG images they generate,
including the current date/time, shooting conditions (e.g. whether a flash was used),
camera settings (shutter, aperture, focal length), etc. Adobe Photoshop,
the leading image editing package, is also capable of embedding
various pieces of metadata into the JPEGs it produces, such as an author, title, copyright notice, etc.
The format for camera-embedded metadata is called EXIF, which stands for
Exchangeable Image File Format.
For more information on EXIF, visit www.exif.org.
The format used by Photoshop is described by the International Press Telecommunications Council
(www.iptc.org)
and usually referred to as IPTC.
AspJpeg 1.4+ is capable of extracting EXIF and IPTC metadata from JPEG images via the OpenInfo and
OpenInfoBinary methods. The difference between the two is the same as between Open
and OpenBinary - the former opens a source image from disk, the latter from memory.
The OpenInfo and OpenInfoBinary methods both return an instance of the Info object
which is a collection of InfoItem objects, each representing a separate EXIF or IPTC field.
The InfoItem object supports the following properties: Name (String), Value (Variant, default property), Tag (Integer),
and Description (String).
The following code sample extracts and displays all metadata fields from a JPEG image:
VB Script:
<%
' Directory with images
Path = Server.MapPath("../images/photo.jpg")
Set Jpeg = Server.CreateObject("Persits.Jpeg")
' Open image for metadata exraction
Set Info = Jpeg.OpenInfo( Path )
' Display collection of items
For Each Item in Info
Response.Write "<TR><TD>"
Response.Write Item.Name & "</TD><TD>"
Response.Write Item.Description & "</TD><TD>"
Response.Write Item.Value & "</TD>"
Response.Write "</TD></TR>"
Next
%>
|
C#:
<script runat="server" LANGUAGE="C#">
void Page_Load(Object Source, EventArgs E)
{
IASPJpeg objJpeg;
objJpeg = new ASPJpeg();
// Compute path to source image
String strPath = Server.MapPath("../images/photo.jpg");
// Open source image for metadata exraction
IInfo objInfo = objJpeg.OpenInfo( strPath );
foreach( IInfoItem objItem in objInfo )
{
TableRow objRow = new TableRow();
TableCell objCell1 = new TableCell();
objCell1.Controls.Add( new LiteralControl( objItem.Name ) );
TableCell objCell2 = new TableCell();
objCell2.Controls.Add(new LiteralControl(objItem.Description));
TableCell objCell3 = new TableCell();
objCell3.Controls.Add(
new LiteralControl( objItem.Value.ToString() ) );
objRow.Cells.Add( objCell1 );
objRow.Cells.Add( objCell2 );
objRow.Cells.Add( objCell3 );
objTable.Rows.Add( objRow );
}
}
</script>
|
Click the links below to run this code sample:
http://localhost/aspjpeg/manual_07/07_metadata.asp
http://localhost/aspjpeg/manual_07/07_metadata.aspx
To obtain a value for a specific metadata field, such as a camera make, you should use
Info's default Item property which accepts this field's name as an index.
Since Item is the default property, the word "Item" can be omitted. In C#, square brackets
must be used. The following code snippet obtains camera make information and assigns it to a string variable:
VB Script:
C#:
String s = Info["Make"].Value;
|
All valid EXIF and IPTC field names are listed below.