A dumb FITS image library for PHP...
Go to file
2024-12-27 16:26:52 +01:00
src Test mono / color images (WIP) 2024-12-27 16:26:52 +01:00
tests Test mono / color images (WIP) 2024-12-27 16:26:52 +01:00
.gitignore Test mono / color images (WIP) 2024-12-27 16:26:52 +01:00
composer.json Test FitsHeader#keyword method 2024-12-25 13:02:28 +01:00
phpdoc.dist.xml Add some tests + phpdoc 2024-12-23 22:19:37 +01:00
README.md Separate multi-block comments; update README 2024-12-24 15:01:55 +01:00

FitsPHP - A dumb FITS image library for PHP

FitsPHP (or fits-php) is a dumb and crappy "library" to somehow interact with the FITS image format used in astronomy.
The library tries to implement a reasonable subset of the FITS standard. Of course, it all depends on the definition of 'reasonable'...

It should allow for the image to be displayed in a browser or even a terminal (yeah, right...).

Why

Why not? But seriously, this doesn't make any sense, you should never use it in any circumstance whatsoever!

Usage

Add the package with Composer:

composer require dumbastro/fits-php

then use classes from the Dumbastro\FitsPhp namespace. More info in the documentation.

Examples

Retrieve the image blob for a given FITS file then do something with the bytes.
The method ImageBlob::dataBytes returns a Generator.

<?php

declare(strict_types=1);

use Dumbastro\FitsPhp\Fits;
use Dumbastro\FitsPhp\ImageBlob;

$fits = new Fits('bubble_nebula.fit');
$blob = new ImageBlob($fits->header(), $fits->imageBlob);

foreach ($blob->dataBytes() as $byte) {
    // Do something useful...
}

Read a specific keyword value from the FITS header. In this example, BITPIX is read which represents the bit depth (bits per pixel) of the image. The bitpix is also a property of the image blob, represented by a PHP Enum. Calling the type() method on the property returns a string with the following possible values (assuming the bitpix is valid in the first place):

Bitpix value Type string Interpretation
8 int8 Character or unsigned binary integer
16 int16 16 bit two's complement binary integer
32 int32 32 bit two's complement binary integer
64 int64 64 bit two's complement binary integer
-32 float32 IEEE single-precision floating point
-64 float64 IEEE double-precision floating point
<?php

declare(strict_types=1);

use Dumbastro\FitsPhp\Fits;
use Dumbastro\FitsPhp\FitsHeader;
use Dumbastro\FitsPhp\ImageBlob;

$fits = new Fits('bubble_nebula.fit'); // Bit-depth is 32-bit unsigned (for example)
$fitsHeader = new FitsHeader($fits->headerBlock);
$bitpix = (int) $fitsHeader->keyword('BITPIX')->value;

// Or, with the image blob
$blob = new ImageBlob($header, $fits->imageBlob);
echo $blob->bitpix->type(); //int32

TODO

  • Separate the main data table (actual image data) from the header (partly done? Who knows...)
  • Read keywords from the FITS header (but consider values and comments could be more than 80-bytes long)
  • History keywords?
  • FITS extensions? What to do with NAXIS > 2?
  • Actually display the image in the standard output (with SVG?)
  • Save the image to PNG and JPG
  • Manipulate the bits using basic processing algorithms??