/** * Composites an Earth-scale indicator * * @param object $imagickImage An Imagick object * * @return void */ private function _addEarthScale($imagickImage) { $rect_width = 73; $rect_height = 56; // Calculate earth scale in piexls $rsunInArcseconds = 959.705; $earthFractionOfSun = 1 / 109.1; $earthScaleInPixels = round(2 * $earthFractionOfSun * ($rsunInArcseconds / $this->roi->imageScale())); // Convert x,y position of top left of EarthScale rectangle // from arcseconds to pixels if ($this->scaleX != 0 && $this->scaleY != 0) { $topLeftX = ($this->scaleX - $this->roi->left()) / $this->roi->imageScale(); $topLeftY = (-$this->scaleY - $this->roi->top()) / $this->roi->imageScale(); } else { $topLeftX = -1; $topLeftY = $imagickImage->getImageHeight() - $rect_height; } // Draw black rectangle background for indicator and label $draw = new ImagickDraw(); $draw->setFillColor('#00000066'); $draw->setStrokeColor('#888888FF'); $draw->rectangle($topLeftX, $topLeftY, $topLeftX + $rect_width, $topLeftY + $rect_height); $imagickImage->drawImage($draw); // Draw Earth to scale if ($earthScaleInPixels >= 1) { $earth = new IMagick(HV_ROOT_DIR . '/resources/images/earth.png'); $x = 1 + $topLeftX + $rect_width / 2 - $earthScaleInPixels / 2; $y = 8 + $topLeftY + $rect_height / 2 - $earthScaleInPixels / 2; $earth->resizeImage($earthScaleInPixels, $earthScaleInPixels, Imagick::FILTER_LANCZOS, 1); $imagickImage->compositeImage($earth, IMagick::COMPOSITE_DISSOLVE, $x, $y); } // Draw grey rectangle background for text label $draw = new ImagickDraw(); $draw->setFillColor('#333333FF'); $draw->rectangle($topLeftX + 1, $topLeftY + 1, $topLeftX + $rect_width - 1, $topLeftY + 16); $imagickImage->drawImage($draw); // Write 'Earth Scale' label in white $text = new IMagickDraw(); $text->setTextEncoding('utf-8'); $text->setFont(HV_ROOT_DIR . '/../resources/fonts/DejaVuSans.ttf'); $text->setFontSize(10); $text->setFillColor('#ffff'); $text->setTextAntialias(true); $text->setStrokeWidth(0); $x = $topLeftX + 9; $y = $topLeftY + 13; $imagickImage->annotateImage($text, $x, $y, 0, 'Earth Scale'); // Cleanup if (isset($draw)) { $draw->destroy(); } if (isset($earth)) { $earth->destroy(); } if (isset($text)) { $text->destroy(); } }