Monday, November 08, 2010 at 12:03 AM.

system.verbs.builtins.html.getJpegHeightWidth

on getJpegHeightWidth (f) {
	<<Changes:
		<<5/2/09; 7:01:55 PM by DW
			<<Maintain a cache of heights and widths in cache.root.
		<<10/20/99; at 2:57:07 PM by PBS
			<<Like html.getGifHeightWidth, it now supports addresses. It does still write the file out to disk, but in a temporary location, in Guest Databases/ops/Temporary Items/. After writing out the file, it deletes it.
	on kernelcall (f) {
		kernel (string.getJpegHeightWidth)};
	if typeOf (f) == addressType { //write the file to disk in a temporary location
		local (tempFolder = Frontier.getSubFolder ("ops/Temporary Items/"));
		if not (file.exists (tempFolder)) {
			file.newFolder (tempFolder)};
		local (tempFilePath = file.uniqueName ("tempJpeg", tempFolder, 7));
		file.writeWholeFile (tempFilePath, f^, 'JPEG', user.html.prefs.imgFileCreator, clock.now ());
		local (hwList);
		hwList = kernelcall (tempFilePath);
		file.delete (tempFilePath);
		return (hwList)}
	else {
		local (adrcache);
		bundle { //init the cache
			local (fmod = file.modified (f));
			adrcache = mainresponder.cache.getCacheTable ();
			adrcache = @adrcache^.html;
			if not defined (adrcache^) {
				new (tabletype, adrcache)};
			adrcache = @adrcache^.hwCache;
			if not defined (adrcache^) {
				new (tabletype, adrcache)};
			adrcache = @adrcache^.[f];
			if defined (adrcache^) {
				if fmod == adrcache^.modified {
					return (adrcache^.hw)}};
			new (tabletype, adrcache);
			adrcache^.modified = fmod;
			local (tc = clock.ticks ());
			adrcache^.hw = kernelcall (f);
			adrcache^.ticsToReadFile = clock.ticks () - tc;
			return (adrcache^.hw)}}}
<<bundle //test code
	<<dialog.alert (getJpegHeightWidth (@websites.samples.["#images"].wozJobs))
	<<dialog.alert (getJpegHeightWidth ("Ohio:Pictures:Digital Camera:New Orleans:DSCN4483.JPG"))



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.