/** * Extract metadata from JP2 image file's XML header * * @param string $image_filepath Full path to JP2 image file * * @return array A subset of the information stored in the jp2 header */ public function extractJP2MetaInfo($image_filepath) { include_once HV_ROOT_DIR . '/../src/Image/JPEG2000/JP2ImageXMLBox.php'; try { $xmlBox = new Image_JPEG2000_JP2ImageXMLBox($image_filepath); $dimensions = $xmlBox->getImageDimensions(); $refPixel = $xmlBox->getRefPixelCoords(); $imageScale = (double) $xmlBox->getImagePlateScale(); $dsun = (double) $xmlBox->getDSun(); $sunCenterOffsetParams = $xmlBox->getSunCenterOffsetParams(); $layeringOrder = $xmlBox->getLayeringOrder(); // Normalize image scale $imageScale = $imageScale * ($dsun / HV_CONSTANT_AU); $meta = array("scale" => $imageScale, "width" => (int) $dimensions[0], "height" => (int) $dimensions[1], "refPixelX" => (double) $refPixel[0], "refPixelY" => (double) $refPixel[1], "sunCenterOffsetParams" => $sunCenterOffsetParams, "layeringOrder" => $layeringOrder); } catch (Exception $e) { throw new Exception(sprintf("Unable to process XML Header for %s: %s", $image_filepath, $e->getMessage()), 13); } return $meta; }