Codex -> The vb script is needed for the binaryajax script to load the binary data.
Twey -> I corrected the doc type. Made no difference though.
Ok, lets start at the begining. I changed the test page slightly and both IE/FF are having the same issues.
The imageinfo.js script when run will alert() the width variable. But on the actual text.html page the document.write() function does not have access to this variable for some reason and returns undefined. How do I pass this variable from the imageinfo.js script to my main html page so that document.write() has access to it?
Here is the updated code.
The readEXIFData(oFile) function is where the alert() is executed.
http://www.inspiredvisuals.com/test/test/test2.html
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script type="text/javascript" src="binaryajax.js"></script>
<script type="text/javascript" src="imageinfo.js"></script>
<script>readFileData("image.jpg")</script>
</head>
<body>
<script type="text/javascript">document.write('<br>'+width)</script>
</body>
</html>
Code:
/*
* ImageInfo 0.1.2 - A JavaScript library for reading image metadata.
* Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
* MIT License [http://www.nihilogic.dk/licenses/mit-license.txt]
*/
var useRange = true;
var Range = 632;
var iOffset = 2;
var width;
function readFileData(url)
{
BinaryAjax(url,function(http) {findEXIFinJPEG(http.binaryResponse)},null,useRange ? [0, Range] : null)
}
function findEXIFinJPEG(oFile)
{
while (iOffset < oFile.getLength())
{
var iMarker = oFile.getByteAt(iOffset+1, true);
if (iMarker == 225) {return readEXIFData(oFile)}
else {iOffset += 2 + oFile.getShortAt(iOffset+2, true)}
}
}
function readEXIFData(oFile)
{
var oTags = readTags(oFile, (iOffset+18), (EXIF_TiffTags = {0x8769 : "ExifIFDPointer"}));
var oEXIFTags = readTags(oFile, (iOffset+10 + oTags.ExifIFDPointer), (EXIF_Tags = {0xA002 : "PixelXDimension",0xA003 : "PixelYDimension"}));
width=oEXIFTags["PixelXDimension"];
alert(width);
}
function readTags(oFile, iDirStart, oStrings)
{
var oTags = {};
for (var i=0;i<oFile.getShortAt(iDirStart);i++)
{
var strTag = oStrings[oFile.getShortAt(iDirStart + i*12 + 2)];
oTags[strTag] = oFile.getLongAt(iDirStart + i*12 + 10);
}
return oTags;
}
Bookmarks