diff --git a/src/Image/Composite/HelioviewerCompositeImage.php b/src/Image/Composite/HelioviewerCompositeImage.php index 92e1feee..1b5160d8 100644 --- a/src/Image/Composite/HelioviewerCompositeImage.php +++ b/src/Image/Composite/HelioviewerCompositeImage.php @@ -1374,23 +1374,24 @@ private function _addScaleBar($imagickImage) { * @return void */ private function _addWatermark($imagickImage) { + + // paths of the different logos to choose from + $hv_logo = sprintf('%s/resources/images/watermark_circle_small_black_border.png', HV_ROOT_DIR); + $hv_with_url_logo = sprintf("%s/resources/images/watermark_small_black_border.png", HV_ROOT_DIR); + if ( $this->width < 200 || $this->height < 200 ) { return; } - $watermark = new IMagick( HV_ROOT_DIR - . '/resources/images/' - . 'watermark_small_black_border.png'); - - // If the image is too small, use only the circle, not the url, and - // scale it so it fits the image. - if ( $this->width / 300 < 2 ) { - $watermark->readImage( HV_ROOT_DIR - . '/resources/images/' - . 'watermark_circle_small_black_border.png'); - $scale = ($this->width / 2) / 300; - $width = $watermark->getImageWidth(); - $watermark->scaleImage(intval($width * $scale), intval($width * $scale)); + // Default text + URL + $watermark = new IMagick($hv_with_url_logo); + + // If the image is too small, use only the circle, not the url, and scale it so it fits the image. + if ( $this->width < 600 ) { + $watermark->readImage($hv_logo); + $scale = $this->width / 600; + $scaled_watermark_width = intval($watermark->getImageWidth() * $scale); + $watermark->scaleImage($scaled_watermark_width, $scaled_watermark_width); } // For whatever reason, compositeImage() doesn't carry over gravity @@ -1398,8 +1399,8 @@ private function _addWatermark($imagickImage) { // the image rather than the desired gravity. $x = $this->width - $watermark->getImageWidth() - 10; $y = $this->height - $watermark->getImageHeight() - 10; - $imagickImage->compositeImage( - $watermark, IMagick::COMPOSITE_DISSOLVE, intval($x), intval($y) ); + + $imagickImage->compositeImage($watermark, IMagick::COMPOSITE_DISSOLVE, intval($x), intval($y) ); // If the image is too small, text won't fit. Don't put a date string // on it. @@ -1452,10 +1453,20 @@ private function _addTimestampWatermark($imagickImage) { $underText->setStrokeColor($black); $underText->setStrokeAntialias(true); $underText->setStrokeWidth(2); - $imagickImage->annotateImage($underText, $leftPad, $lowerPad, 0, $nameCmd); - $imagickImage->annotateImage($underText, 120+$leftPad, $lowerPad, 0, $timeCmd); + $imagickImage->annotateImage($underText, $leftPad, $lowerPad, 0, $nameCmd); + + // Query font metrics to find out area width of the satellite image sources text (ex: SDO AIA 404) + // Then we use this width to calculate where to put timestamps outline in image + // last parameter true means multiline text + $underTextQueryMetrics = $imagickImage->queryFontMetrics($underText, $nameCmd, true); - // Write words in white over outline + // 10 is the default padding between source outline and timestamp outline + $underTextRightPad = $underTextQueryMetrics['textWidth'] ? ($underTextQueryMetrics['textWidth'] + 10) : 120; + + // Place timestamp outline + $imagickImage->annotateImage($underText, $underTextRightPad + $leftPad, $lowerPad, 0, $timeCmd); + + // Write text in white over the outline $text = new IMagickDraw(); $text->setTextEncoding('utf-8'); $text->setFont(HV_ROOT_DIR.'/../resources/fonts/DejaVuSans.ttf'); @@ -1463,8 +1474,18 @@ private function _addTimestampWatermark($imagickImage) { $text->setFillColor($white); $text->setTextAntialias(true); $text->setStrokeWidth(0); - $imagickImage->annotateImage($text, $leftPad, $lowerPad, 0, $nameCmd); - $imagickImage->annotateImage($text, 120+$leftPad, $lowerPad, 0, $timeCmd); + $imagickImage->annotateImage($text, $leftPad, $lowerPad, 0, $nameCmd); + + // Query font metrics to find out area width of the satellite image sources text (ex: SDO AIA 404) + // Then we use this width to calculate where to put timestamps texts in image. + // last parameter true means multiline text + $textQueryMetrics = $imagickImage->queryFontMetrics($text , $nameCmd, true); + + // 10 is the default padding between source text and timestamp text + $textRightPad = $textQueryMetrics['textWidth'] ? ($textQueryMetrics['textWidth'] + 10) : 120; + + // Place timestamp text + $imagickImage->annotateImage($text, $textRightPad + $leftPad, $lowerPad, 0, $timeCmd); // Cleanup $black->destroy(); diff --git a/src/Image/HelioviewerImage.php b/src/Image/HelioviewerImage.php index bd010910..0735523c 100644 --- a/src/Image/HelioviewerImage.php +++ b/src/Image/HelioviewerImage.php @@ -96,7 +96,7 @@ private function _imageNotVisible($pixelRoi) { * @return string watermark name */ public function getWaterMarkName() { - return $this->getWaterMarkName(); + return trim(join(' ', array_column($this->uiLabels, 'name'))) . "\n"; } /** diff --git a/src/Image/ImageType/AIAImage.php b/src/Image/ImageType/AIAImage.php index 36725745..c61e0d12 100644 --- a/src/Image/ImageType/AIAImage.php +++ b/src/Image/ImageType/AIAImage.php @@ -51,18 +51,5 @@ public function __construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY parent::__construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY, $options); } - - /** - * Gets a string that will be displayed in the image's watermark - * - * @return string watermark name - */ - public function getWaterMarkName() { - $name = $this->uiLabels[2]['name']; - if($this->uiLabels[2]['name'] == 'AIA'){ - $name = $this->uiLabels[3]['name']; - } - return 'AIA '.$name."\n"; - } } ?> diff --git a/src/Image/ImageType/CORImage.php b/src/Image/ImageType/CORImage.php index 2414b665..f6c688c0 100644 --- a/src/Image/ImageType/CORImage.php +++ b/src/Image/ImageType/CORImage.php @@ -52,16 +52,6 @@ public function __construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY parent::__construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY, $options); } - /** - * Gets a string that will be displayed in the image's watermark - * - * @return string Watermark name - */ - public function getWaterMarkName() { - $which = substr($this->uiLabels[0]['name'], -1); - return $this->uiLabels[2]['name'].'-'.$which."\n"; - } - /** * Generates a portion of an ImageMagick convert command to apply * an alpha mask diff --git a/src/Image/ImageType/COSMOImage.php b/src/Image/ImageType/COSMOImage.php index dfad3d72..96d27285 100644 --- a/src/Image/ImageType/COSMOImage.php +++ b/src/Image/ImageType/COSMOImage.php @@ -41,15 +41,6 @@ public function __construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY parent::__construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY, $options); } - /** - * Gets a string that will be displayed in the image's watermark - * - * @return string Watermark name - */ - public function getWaterMarkName() { - return 'COSMO_K-Coronagraph '.$this->uiLabels[2]['name']."\n"; - } - /** * Generates a portion of an ImageMagick convert command to apply an alpha mask * @@ -166,4 +157,4 @@ protected function setAlphaChannel(&$imagickImage) { $mask->destroy(); } } -?> \ No newline at end of file +?> diff --git a/src/Image/ImageType/EITImage.php b/src/Image/ImageType/EITImage.php index d5ba67ac..1cc78972 100644 --- a/src/Image/ImageType/EITImage.php +++ b/src/Image/ImageType/EITImage.php @@ -46,16 +46,5 @@ public function __construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY parent::__construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY, $options); } - - /** - * Gets a string that will be displayed in the image's watermark - * - * @return string watermark name - */ - public function getWaterMarkName() { - $labelName = isset($this->uiLabels[3]) ? $this->uiLabels[3]['name'] : $this->uiLabels[2]['name']; - return 'EIT '.$labelName."\n"; - } - } -?> \ No newline at end of file +?> diff --git a/src/Image/ImageType/EUIImage.php b/src/Image/ImageType/EUIImage.php index da1cb365..95d29b3c 100644 --- a/src/Image/ImageType/EUIImage.php +++ b/src/Image/ImageType/EUIImage.php @@ -44,17 +44,5 @@ public function __construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY parent::__construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY, $options); } - - /** - * Gets a string that will be displayed in the image's watermark - * - * @return string watermark name - */ - public function getWaterMarkName() { - $type = $this->uiLabels[2]['name']; - $measurement = $this->uiLabels[3]['name']; - $watermark = 'EUI '.$type.' '.$measurement." Å\n"; - return $watermark; - } } ?> diff --git a/src/Image/ImageType/EUVIImage.php b/src/Image/ImageType/EUVIImage.php index a498ca3a..441b0596 100644 --- a/src/Image/ImageType/EUVIImage.php +++ b/src/Image/ImageType/EUVIImage.php @@ -38,15 +38,5 @@ public function __construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY parent::__construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY, $options); } - - /** - * Gets a string that will be displayed in the image's watermark - * - * @return string watermark name - */ - public function getWaterMarkName() { - $which = substr($this->uiLabels[0]['name'], -1); - return 'EUVI-'.$which.' '.$this->uiLabels[3]['name']."\n"; - } } -?> \ No newline at end of file +?> diff --git a/src/Image/ImageType/GONGImage.php b/src/Image/ImageType/GONGImage.php index 0ff346bf..ae38e4fe 100644 --- a/src/Image/ImageType/GONGImage.php +++ b/src/Image/ImageType/GONGImage.php @@ -44,15 +44,5 @@ protected function setColorPalette(&$input) { return false; } - /** - * Gets a string that will be displayed in the image's watermark - * - * @return string watermark name - */ - public function getWaterMarkName() { - $labelName = $this->uiLabels[2]['name']; - return 'GONG '.$labelName."\n"; - } - } -?> \ No newline at end of file +?> diff --git a/src/Image/ImageType/HMIImage.php b/src/Image/ImageType/HMIImage.php index 566993e9..eea58435 100644 --- a/src/Image/ImageType/HMIImage.php +++ b/src/Image/ImageType/HMIImage.php @@ -47,16 +47,5 @@ public function __construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY protected function setColorPalette(&$input) { return false; } - - /** - * Gets a string that will be displayed in the image's watermark - * - * @return string watermark name - */ - public function getWaterMarkName() { - $labelName = isset($this->uiLabels[3]) ? $this->uiLabels[3]['name'] : $this->uiLabels[2]['name']; - return 'HMI '.$labelName."\n"; - } - } -?> \ No newline at end of file +?> diff --git a/src/Image/ImageType/LASCOImage.php b/src/Image/ImageType/LASCOImage.php index e97303f1..aa88d13f 100644 --- a/src/Image/ImageType/LASCOImage.php +++ b/src/Image/ImageType/LASCOImage.php @@ -48,15 +48,6 @@ public function __construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY parent::__construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY, $options); } - /** - * Gets a string that will be displayed in the image's watermark - * - * @return string Watermark name - */ - public function getWaterMarkName() { - return 'LASCO '.$this->uiLabels[2]['name']."\n"; - } - /** * Generates a portion of an ImageMagick convert command to apply an alpha mask * @@ -175,4 +166,4 @@ protected function setAlphaChannel(&$imagickImage) { $mask->destroy(); } } -?> \ No newline at end of file +?> diff --git a/src/Image/ImageType/MDIImage.php b/src/Image/ImageType/MDIImage.php index 419e2c1f..3d3eef85 100644 --- a/src/Image/ImageType/MDIImage.php +++ b/src/Image/ImageType/MDIImage.php @@ -46,16 +46,5 @@ public function __construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY protected function setColorPalette(&$input) { return false; } - - /** - * Gets a string that will be displayed in the image's watermark - * - * @return string watermark name - */ - public function getWaterMarkName() { - $labelName = isset($this->uiLabels[3]) ? $this->uiLabels[3]['name'] : $this->uiLabels[2]['name']; - return 'MDI '.$labelName."\n"; - } - } -?> \ No newline at end of file +?> diff --git a/src/Image/ImageType/RHESSIImage.php b/src/Image/ImageType/RHESSIImage.php index fce29f0d..18f478a4 100644 --- a/src/Image/ImageType/RHESSIImage.php +++ b/src/Image/ImageType/RHESSIImage.php @@ -31,17 +31,5 @@ public function __construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY $this->setColorTable($color_table); parent::__construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY, $options); } - - /** - * Gets a string that will be displayed in the image's watermark - * - * @return string watermark name - */ - public function getWaterMarkName() { - $observatory = $this->uiLabels[0]['name']; - $energy = $this->uiLabels[1]['name']; - $reconstruction = $this->uiLabels[2]['name']; - return $observatory . " " . $energy . " " . $reconstruction; - } } -?> \ No newline at end of file +?> diff --git a/src/Image/ImageType/SJIImage.php b/src/Image/ImageType/SJIImage.php index 7416e161..7ee1229c 100644 --- a/src/Image/ImageType/SJIImage.php +++ b/src/Image/ImageType/SJIImage.php @@ -34,16 +34,5 @@ public function __construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY parent::__construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY, $options); } - - /** - * Gets a string that will be displayed in the image's watermark - * - * @return string watermark name - */ - public function getWaterMarkName() { - $measurement = $this->uiLabels[2]['name']; - $watermark = 'IRIS SJI '.$measurement." Å\n"; - return $watermark; - } } ?> diff --git a/src/Image/ImageType/SUVIImage.php b/src/Image/ImageType/SUVIImage.php index 003c89e3..8cc1f3d6 100644 --- a/src/Image/ImageType/SUVIImage.php +++ b/src/Image/ImageType/SUVIImage.php @@ -16,6 +16,7 @@ require_once HV_ROOT_DIR.'/../src/Image/HelioviewerImage.php'; class Image_ImageType_SUVIImage extends Image_HelioviewerImage { + /** * Creates a new SUVIImage * @@ -44,17 +45,5 @@ public function __construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY parent::__construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY, $options); } - - /** - * Gets a string that will be displayed in the image's watermark - * - * @return string watermark name - */ - public function getWaterMarkName() { - $type = $this->uiLabels[2]['name']; - $measurement = $this->uiLabels[3]['name']; - $watermark = 'SUVI '.$type.' '.$measurement."\n"; - return $watermark; - } } ?> diff --git a/src/Image/ImageType/SWAPImage.php b/src/Image/ImageType/SWAPImage.php index 1daade68..9256f666 100644 --- a/src/Image/ImageType/SWAPImage.php +++ b/src/Image/ImageType/SWAPImage.php @@ -63,15 +63,5 @@ public function __construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY parent::__construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY, $options); } - - /** - * Gets a string that will be displayed in the image's watermark - * - * @return string watermark name - */ - public function getWaterMarkName() { - return 'SWAP '.(isset($this->uiLabels[3]) ? $this->uiLabels[3]['name'] : $this->uiLabels[2]['name'])."\n"; - } - } -?> \ No newline at end of file +?> diff --git a/src/Image/ImageType/SXTImage.php b/src/Image/ImageType/SXTImage.php index a5c08cd2..35289a5b 100644 --- a/src/Image/ImageType/SXTImage.php +++ b/src/Image/ImageType/SXTImage.php @@ -46,16 +46,5 @@ public function __construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY parent::__construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY, $options); } - - /** - * Gets a string that will be displayed in the image's watermark - * - * @return string watermark name - */ - public function getWaterMarkName() { - $labelName = isset($this->uiLabels[3]) ? $this->uiLabels[3]['name'] : $this->uiLabels[2]['name']; - return 'SXT '.$labelName."\n"; - } - } ?> diff --git a/src/Image/ImageType/TRACEImage.php b/src/Image/ImageType/TRACEImage.php index 8afb0dba..64912572 100644 --- a/src/Image/ImageType/TRACEImage.php +++ b/src/Image/ImageType/TRACEImage.php @@ -39,15 +39,5 @@ public function __construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY parent::__construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY, $options); } - - /** - * Gets a string that will be displayed in the image's watermark - * - * @return string watermark name - */ - public function getWaterMarkName() { - return 'TRACE '.$this->uiLabels[1]['name']."\n"; - } - } -?> \ No newline at end of file +?> diff --git a/src/Image/ImageType/XRTImage.php b/src/Image/ImageType/XRTImage.php index 72476eb1..f38e6d0e 100644 --- a/src/Image/ImageType/XRTImage.php +++ b/src/Image/ImageType/XRTImage.php @@ -36,7 +36,6 @@ class Image_ImageType_XRTImage extends Image_HelioviewerImage { public function __construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY, $options, $sunCenterOffsetParams, $name = '') { $this->uiLabels = $uiLabels; - $this->name = $name; $colorTable = HV_ROOT_DIR.'/resources/images/color-tables/Hinode_XRT.png'; @@ -49,14 +48,4 @@ public function __construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY parent::__construct($jp2, $filepath, $roi, $uiLabels, $offsetX, $offsetY, $options); } - - /** - * Gets a string that will be displayed in the image's watermark - * - * @return string watermark name - */ - public function getWaterMarkName() { - //return 'XRT '.$this->uiLabels[2]['name'].' ' .(isset($this->uiLabels[3]['name']) ? $this->uiLabels[3]['name'] : '')."\n"; - return $this->name ."\n"; - } }