Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/watermarks overflow #422

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 41 additions & 20 deletions src/Image/Composite/HelioviewerCompositeImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -1374,32 +1374,33 @@ 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
// settings so the offsets must be relative to the top left corner of
// 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.
Expand Down Expand Up @@ -1452,19 +1453,39 @@ 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');
$text->setFontSize(12);
$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();
Expand Down
2 changes: 1 addition & 1 deletion src/Image/HelioviewerImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

/**
Expand Down
13 changes: 0 additions & 13 deletions src/Image/ImageType/AIAImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
?>
10 changes: 0 additions & 10 deletions src/Image/ImageType/CORImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 1 addition & 10 deletions src/Image/ImageType/COSMOImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -166,4 +157,4 @@ protected function setAlphaChannel(&$imagickImage) {
$mask->destroy();
}
}
?>
?>
13 changes: 1 addition & 12 deletions src/Image/ImageType/EITImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

}
?>
?>
12 changes: 0 additions & 12 deletions src/Image/ImageType/EUIImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
?>
12 changes: 1 addition & 11 deletions src/Image/ImageType/EUVIImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
?>
?>
12 changes: 1 addition & 11 deletions src/Image/ImageType/GONGImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

}
?>
?>
13 changes: 1 addition & 12 deletions src/Image/ImageType/HMIImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

}
?>
?>
11 changes: 1 addition & 10 deletions src/Image/ImageType/LASCOImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -175,4 +166,4 @@ protected function setAlphaChannel(&$imagickImage) {
$mask->destroy();
}
}
?>
?>
13 changes: 1 addition & 12 deletions src/Image/ImageType/MDIImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

}
?>
?>
14 changes: 1 addition & 13 deletions src/Image/ImageType/RHESSIImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
?>
?>
11 changes: 0 additions & 11 deletions src/Image/ImageType/SJIImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
?>
13 changes: 1 addition & 12 deletions src/Image/ImageType/SUVIImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
require_once HV_ROOT_DIR.'/../src/Image/HelioviewerImage.php';

class Image_ImageType_SUVIImage extends Image_HelioviewerImage {

/**
* Creates a new SUVIImage
*
Expand Down Expand Up @@ -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;
}
}
?>
12 changes: 1 addition & 11 deletions src/Image/ImageType/SWAPImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

}
?>
?>
11 changes: 0 additions & 11 deletions src/Image/ImageType/SXTImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

}
?>
Loading
Loading