Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


FITS is the Flexible Image Transport System and is widely used in astronomy for holding observation data. There are many FITS I/O libraries available in a variety of languages. This is an attempt to build a FITS library for Javascript to allow FITS files to be displayed in a modern web browser. Given that FITS files have no compression they are quite large so I imagine this library will be more useful when run locally. By displaying the image using in the browser, it will be very easy to save a FITS image as a standard graphics file.


For this library to work it has two dependencies:

  • binaryajax.js -- this does the XMLHttpRequest and the bit extraction. It is created by Jacob Seidelin and is only about 6.2 kB;
  • excanvas.js -- this is used to allow canvas support on Internet Explorer (41.6 kB).


Due to web browser cross-domain security issues, any FITS file you want to read must be hosted on the same domain as the code.


You need to include the appropriate Javascript files:

<script src="binaryajax.js"></script>
<script src="excanvas.js"></script>
<script src="fits.js"></script>

Following those you can define your FITS object:

var fits = new FITS();

Next we define what happens on load:


	// Display some values
	document.getElementById('bitpix').innerHTML = this.header.BITPIX;
	document.getElementById('depth').innerHTML = this.depth;
	document.getElementById('z').value = 0;

	this.draw("FITSimage")	// Draw the image to the element with id=FITSimage

We can also bind some other events (which are chainable) e.g.:

	e.y = this.height - e.y
	var value =this.image[e.y*this.width+e.x];
	document.getElementById('status').innerHTML ='click=('+ e.x+','+e.y+')='+value;
	e.y = this.height - e.y
	var value =this.image[e.y*this.width+e.x];
	document.getElementById('status').innerHTML ='move=('+ e.x+','+e.y+')='+value;

Finally, load the FITS file. We've already defined the load event above:


FITS files

The example makes use of several FITS files. You can get these at:


Stuart Lowe works for the Las Cumbres Observatory Global Telescope. LCOGT is a private operating foundation, building a global network of telescopes for professional research and citizen investigations.

Some improvements have been suggested by anonymous contributors.


A Javascript library to read and display FITS files in a browser



No releases published
You can’t perform that action at this time.