# 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](https://fits.gsfc.nasa.gov/fits_standard.html). 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 **NOTE: Not added to Packagist yet...** Add the package with Composer: ``` composer require dumbastro/fits-php ``` then use classes from the `Dumbastro\FitsPhp` namespace. ### Examples Retrieve the image blob for a given FITS file then do something with the bytes. The method `ImageBlob::dataBytes` returns a `Generator`. ```php 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 headerBlock); $bitpix = (int) $fitsHeader->keyword('BITPIX')->value; // Or, with the image blob $blob = new ImageBlob($header, $fits->imageBlob); echo $blob->bitpix->type(); //int32 ``` ## TODO - [x] Separate the main data table (actual image data) from the header (partly done? Who knows...) - [x] Read keywords from the FITS header (COMMENT keywords could be buggy) - [ ] History keywords? - [ ] FITS extensions? - [ ] Actually display the image in the standard output - [ ] Save the image to PNG and/or JPG - [ ] Manipulate the bits using basic processing algorithms??