CycloneChris
Technical User
Hey,
I am trying to access the width variable from my main page. Within the imageinfo.js script functions I can alert() the width value which returns 1024. But I can't seem to pass this variable to my main page or access it directly so that I can use document.write() to write the variable on the page. Whenever I try to call the 'width' variable directly from the main page I get undefined. How can I access this variable?
However, with the test code below, I was able to get ducument.write() to write the 'width' variable on the page but now the page doesn't stop loading - there's an endless loop in the code...
I think the problem is with this line but I'm not sure.
Test page
http://www.inspiredvisuals.com/test/test/test3.html
Main page
Imageinfo script - This script uses the binaryajax script found here. http://www.inspiredvisuals.com/test/test/binaryajax.js
Thanks for the help.
I am trying to access the width variable from my main page. Within the imageinfo.js script functions I can alert() the width value which returns 1024. But I can't seem to pass this variable to my main page or access it directly so that I can use document.write() to write the variable on the page. Whenever I try to call the 'width' variable directly from the main page I get undefined. How can I access this variable?
However, with the test code below, I was able to get ducument.write() to write the 'width' variable on the page but now the page doesn't stop loading - there's an endless loop in the code...
I think the problem is with this line but I'm not sure.
Code:
BinaryAjax(url,function(http) {findEXIFinJPEG(http.binaryResponse);test(width)},null,useRange ? [0, Range] : null);
Test page
http://www.inspiredvisuals.com/test/test/test3.html
Main page
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]
<html>
<head>
<script>
function test(width)
{
document.write('Image Width = ' + width)
}
</script>
<script type="text/javascript" src="binaryajax.js"></script>
<script type="text/javascript" src="imageinfo.js"></script>
</head>
<body>
<script type="text/javascript">readFileData('image.jpg')</script>
</body>
</html>
Imageinfo script - This script uses the binaryajax script found here. http://www.inspiredvisuals.com/test/test/binaryajax.js
Code:
/*
* ImageInfo 0.1.2 - A JavaScript library for reading image metadata.
* Copyright (c) 2008 Jacob Seidelin, [email]jseidelin@nihilogic.dk[/email], [url]http://blog.nihilogic.dk/[/url]
* MIT License [[url]http://www.nihilogic.dk/licenses/mit-license.txt][/url]
*/
var useRange = true;
var Range = 632;
var iOffset = 2;
var width;
function readFileData(url)
{
BinaryAjax(url,function(http) {findEXIFinJPEG(http.binaryResponse);test(width)},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"];
}
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;
}
Thanks for the help.