public function writeWatermarkInfo(&$sourcefileId, $thumbnailMode, CacheFile $cacheFile)
 {
     if (!$this->config->isUsedWatermark() || $thumbnailMode) {
         return;
     }
     static $disable_alpha_warning;
     $watermarkfile = $this->config->getWatermarkFile();
     $align = $this->config->getWatermarkLeft();
     $valign = $this->config->getWatermarkTop();
     if ($this->config->getWatermarkTransparencyType() == 'alpha') {
         $transcolor = FALSE;
     } else {
         $transcolor = $this->config->getWatermarkTransparentColor();
     }
     $transparency = $this->config->getWatermarkTransparency();
     try {
         $watermarkfile_id = $this->loadWatermarkFile($watermarkfile);
     } catch (Exception $e) {
         return false;
     }
     @imageAlphaBlending($watermarkfile_id, false);
     $result = @imageSaveAlpha($watermarkfile_id, true);
     if (!$result) {
         if (!$disable_alpha_warning) {
             $msg = "Watermark problem: your server does not support alpha blending (requires GD 2.0.1+)";
             JLog::add($msg, JLog::WARNING);
         }
         $disable_alpha_warning = true;
         imagedestroy($watermarkfile_id);
         return false;
     }
     $offset_w = $cacheFile->offsetX();
     $offset_h = $cacheFile->offsetY();
     $w = $cacheFile->displayWidth();
     $h = $cacheFile->displayHeight();
     $watermarkfileWidth = imageSX($watermarkfile_id);
     $watermarkfileHeight = imageSY($watermarkfile_id);
     $watermarkOffsetX = $this->calcXOffsetForWatermark($align, $watermarkfileWidth, $offset_w, $w);
     $watermarkOffsetY = $this->calcYOffsetForWatermark($valign, $watermarkfileHeight, $offset_h, $h);
     $fileType = strtolower(pathinfo($watermarkfile, PATHINFO_EXTENSION));
     $sourcefileId = $this->upsampleImageIfNecessary($fileType, $sourcefileId);
     if ($transcolor !== false) {
         $transcolAsInt = intval(str_replace('#', '', $transcolor), 16);
         imagecolortransparent($watermarkfile_id, $transcolAsInt);
         // use transparent color
         imagecopymerge($sourcefileId, $watermarkfile_id, $watermarkOffsetX, $watermarkOffsetY, 0, 0, $watermarkfileWidth, $watermarkfileHeight, $transparency);
     } else {
         imagecopy($sourcefileId, $watermarkfile_id, $watermarkOffsetX, $watermarkOffsetY, 0, 0, $watermarkfileWidth, $watermarkfileHeight);
         // True
         // alphablend
     }
     imagedestroy($watermarkfile_id);
     return true;
 }
Example #2
0
 public static function buildHtmlForImage(&$lightbox, CacheFile &$mosthumbProperties, CacheFile &$mosimageProperties, ImageProperties &$imgProperties, &$config, $param)
 {
     $accessLevel = $imgProperties->getAccessLevel();
     $user = JFactory::getUser();
     if ($user->guest && $accessLevel > 1) {
         $img = '';
     } else {
         $lightboxRel = $lightbox->getRel();
         $thumbSize = ' width="' . $mosthumbProperties->displayWidth() . '" height="' . $mosthumbProperties->displayHeight() . '"';
         $image = '<a href="' . $mosimageProperties->getCacheFileUrl() . '"';
         $image .= ' rel="' . $lightboxRel . '"';
         $image .= ' class="' . $lightbox->getCssClassForImageLink() . '"';
         $image .= ' title="' . ($config->isViewCaptionTextForFullsize() ? $imgProperties->getCaptionText() : '') . '"';
         $image .= '>';
         $image .= '<img class="mosimgage-inner" src="' . $mosthumbProperties->getCacheFileUrl() . '"';
         $image .= $thumbSize;
         $image .= $imgProperties->getImageAlignAsHtml();
         $image .= ' alt="' . $imgProperties->getAltText() . '"';
         $image .= ' title="' . $imgProperties->getCaptionText() . '"';
         $image .= ' border="' . $imgProperties->getBorderWidth() . '"';
         $image .= ' /></a>';
         $caption = '';
         $widthInner = $mosthumbProperties->displayWidth();
         $widthOuter = $mosthumbProperties->displayWidth();
         // + 26 - 12; // -12 img.mosimgage-inner margin- = 0px
         if ($imgProperties->isCaptionTextEmpty()) {
             $cssDisplay = " visibility: hidden;";
         } else {
             $cssDisplay = '';
         }
         $cssClassOuter = $imgProperties->getOuterCssClass();
         $img = '<span class="' . $cssClassOuter . '" style="width: ' . $widthOuter . 'px;border-width:' . $imgProperties->getBorderWidth() . 'px;">';
         if ($imgProperties->isViewCaptionTextForThumbnail()) {
             $caption_valign = $imgProperties->getCaptionPosition();
             $cssWidh = 'width: ' . $widthInner . 'px;';
             $caption = '<span class="mosimgage-inner-' . $caption_valign . '" style="' . $cssWidh . $cssDisplay . '" ';
             $caption .= '>';
             $caption .= $imgProperties->getCaptionText();
             $caption .= '</span>';
             if ($caption_valign == 'top' && $caption) {
                 $img .= $caption;
             }
             $img .= $image;
             if ($caption_valign == 'bottom' && $caption) {
                 $img .= $caption;
             }
         } else {
             $img .= $image;
         }
         $img .= '</span>';
     }
     $addHtml = self::getHtmlForFloat($param);
     return $addHtml . $img;
 }
 /**
  * Erzeugt ein verkleinertes Abbild des Originalbildes.
  */
 private function generateResizedImage(CacheFile $cacheFile, $proportion, $thumbnailMode, $bgcolor = 0xff0000)
 {
     static $countGenerateImage;
     if (!isset($countGenerateImage)) {
         $countGenerateImage = 0;
     }
     $countGenerateImage++;
     if ($thumbnailMode) {
         $minWidth = 50;
         // Wert siehe mosimage.xml => thumb_width => min
     } else {
         $minWidth = 200;
         // Wert siehe mosimage.xml => full_width => min
     }
     $origw = $cacheFile->origWidth();
     $origh = $cacheFile->origHeight();
     $displayWidth = $cacheFile->displayWidth();
     $displayHeight = $cacheFile->displayHeight();
     $src_img =& $this->loadImageFromFile($cacheFile);
     // Behandlung kleiner Bilder
     // - Die original-Höhe ist kleiner als die Zielhöhe. Zielhöhe kann nie 0 sein.
     // - Es bleibt diese Höhe erhalten und wir schneiden ggf. etwas von der Breite weg.
     // - Bei Auto-Breite wird die Breite ggf. auf ein Seitenverhältnis von 2:1 begrenzt, damit
     // das Bild nicht übermäßig breit wird
     if ($origh < $displayHeight) {
         // Im Auto-Modus wird das Seitenverhältnis aus dem Original genmmen
         if ($displayWidth == 0) {
             $displayWidth = intval($origw / $origh * $displayHeight);
             if ($displayWidth > $displayHeight * 2) {
                 // Seitenverhältnis ggf. auf 2:1 reduzieren
                 $displayWidth = $displayHeight * 2;
             }
         }
         // Bild ist auch so schmal, das es reinpasst
         if ($origw < $displayWidth) {
             $offset_w = ($displayWidth - $origw) / 2;
             $offset_h = $this->calcPropertion($displayHeight, $origh, $proportion);
             $src_w = $origw;
             $src_h = $origh;
         } else {
             // ansonsten schneiden wir es rechts ab
             $offset_w = 0;
             $offset_h = $this->calcPropertion($displayHeight, $origh, $proportion);
             $src_w = $displayWidth;
             $src_h = $origh;
         }
         if ($displayWidth < $minWidth) {
             $this->debug($cacheFile, "[Fix auto-Breite] display: [{$displayWidth} x {$displayHeight}] offset: [{$offset_w} x {$offset_h}]");
             $offset_w = ($minWidth - $displayWidth) / 2;
             $displayWidth = $minWidth;
         }
         $cacheFile->setImageOffset($offset_w, $offset_h);
         $cacheFile->setDisplaySize($displayWidth, $displayHeight);
         $this->debug($cacheFile, "[kleine Höhe ] display: [{$displayWidth} x {$displayHeight}] offsetW: [{$offset_w}] offsetH: [{$offset_h}]");
         if ($countGenerateImage > $this->config->getMaxResizedImagePerRequest()) {
             return $this->generatePlaceHolder($cacheFile, $this->config->getScrambleFilename());
         }
         $dst_img = ImageCreateTrueColor($displayWidth, $displayHeight);
         imagefill($dst_img, 0, 0, $bgcolor);
         imagecopy($dst_img, $src_img, $offset_w, $offset_h, 0, 0, $src_w, $src_h);
         $this->watermarkCreator->writeWatermarkInfo($dst_img, $thumbnailMode, $cacheFile);
         $this->writeImageToFile($dst_img, $cacheFile);
         imagedestroy($src_img);
         imagedestroy($dst_img);
         return $cacheFile;
     }
     // Behandlung kleiner Bilder
     // - Die original-Breite ist kleiner als die ZielBreite, Zielbreite ist ungleich 0
     // - Es bleibt diese Breite erhalten und wir schneiden ggf. etwas von der Höhe weg.
     if ($origw < $displayWidth && $displayWidth != 0) {
         // Bild ist auch so hoch, das es reinpasst, das Bild wird dabei zentiert
         if ($origh < $displayHeight) {
             $offset_w = ($displayWidth - $origw) / 2;
             $offset_h = ($displayHeight - $origh) / 2;
             $src_w = $origw;
             $src_h = $origh;
         } else {
             // ansonsten schneiden wir es unten ab
             $offset_w = ($displayWidth - $origw) / 2;
             $offset_h = 0;
             $src_w = $origw;
             $src_h = $displayHeight;
         }
         $cacheFile->setImageOffset($offset_w, $offset_h);
         $this->debug($cacheFile, "[schmal] display: [{$displayWidth} x {$displayHeight}] offsetW: [{$offset_w}] offsetH: [{$offset_h}]");
         if ($countGenerateImage > $this->config->getMaxResizedImagePerRequest()) {
             return $this->generatePlaceHolder($cacheFile, $this->config->getScrambleFilename());
         }
         $dst_img = ImageCreateTrueColor($displayWidth, $displayHeight);
         imagefill($dst_img, 0, 0, $bgcolor);
         imagecopy($dst_img, $src_img, $offset_w, $offset_h, 0, 0, $src_w, $src_h);
         $this->writeImageToFile($dst_img, $cacheFile);
         imagedestroy($src_img);
         imagedestroy($dst_img);
         return $cacheFile;
     }
     // Breite automatisch berechnen, Seitenverhältnis beibehalten, wenn sinnvoll.
     if ($displayWidth == 0) {
         $displayWidth = intval($origw / $origh * $displayHeight);
         $offset_w = 0;
         $offset_h = 0;
         $w = $displayWidth;
         $h = $displayHeight;
         if ($displayWidth < $minWidth) {
             $this->debug($cacheFile, "[Fix auto-Breite] display: [{$displayWidth} x {$displayHeight}] offset: [{$offset_w} x {$offset_h}]");
             $offset_w = ($minWidth - $displayWidth) / 2;
             $displayWidth = $minWidth;
         }
         $cacheFile->setImageOffset($offset_w, $offset_h);
         $cacheFile->setDisplaySize($displayWidth, $displayHeight);
         $this->debug($cacheFile, "[auto-Breite] display: [{$displayWidth} x {$displayHeight}] offset: [{$offset_w} x {$offset_h}]");
         if ($countGenerateImage > $this->config->getMaxResizedImagePerRequest()) {
             return $this->generatePlaceHolder($cacheFile, $this->config->getScrambleFilename());
         }
         $dst_img = ImageCreateTrueColor($displayWidth, $displayHeight);
         imagefill($dst_img, 0, 0, $bgcolor);
         imagecopyresampled($dst_img, $src_img, $offset_w, $offset_h, 0, 0, $w, $h, $origw, $origh);
         $this->watermarkCreator->writeWatermarkInfo($dst_img, $thumbnailMode, $cacheFile);
         $this->writeImageToFile($dst_img, $cacheFile);
         imagedestroy($src_img);
         imagedestroy($dst_img);
         return $cacheFile;
     }
     // - Zielbreite ist bekannt und
     // - Original-Bilder ist größer als Zielbild
     if ($displayWidth != 0 && $displayHeight != 0) {
         if ($origw > $origh) {
             // landscape
             if ($displayWidth > $displayHeight) {
                 $w = $origw / $origh * $displayHeight;
                 $h = $displayHeight;
                 $offset_w = ($displayWidth - $w) / 2;
                 $offset_h = 0;
             } else {
                 $w = $displayWidth;
                 $h = $origh / $origw * $displayWidth;
                 $offset_w = 0;
                 $offset_h = $this->calcPropertion($displayHeight, $h, $proportion);
             }
         } else {
             // portrait
             if ($displayWidth >= $displayHeight) {
                 // Zielbild ist Landcape
                 $w = $origw / $origh * $displayHeight;
                 $h = $displayHeight;
                 $offset_w = ($displayWidth - $w) / 2;
                 $offset_h = 0;
             } else {
                 $w = $displayWidth;
                 $h = $origh / $origw * $displayWidth;
                 $offset_w = 0;
                 $offset_h = $this->calcPropertion($displayHeight, $h, $proportion);
             }
         }
         $cacheFile->setImageOffset($offset_w, $offset_h);
         $cacheFile->setDisplaySize($displayWidth, $displayHeight);
         $this->debug($cacheFile, "[normal] display: [{$displayWidth} x {$displayHeight}]  content [{$w} x {$h}] offset: [{$offset_w} x {$offset_h}]");
         if ($countGenerateImage > $this->config->getMaxResizedImagePerRequest()) {
             return $this->generatePlaceHolder($cacheFile, $this->config->getScrambleFilename());
         }
         $dst_img = ImageCreateTrueColor($displayWidth, $displayHeight);
         imagefill($dst_img, 0, 0, $bgcolor);
         imagecopyresampled($dst_img, $src_img, $offset_w, $offset_h, 0, 0, $w, $h, $origw, $origh);
         $this->watermarkCreator->writeWatermarkInfo($dst_img, $thumbnailMode, $cacheFile);
         $this->writeImageToFile($dst_img, $cacheFile);
         imagedestroy($src_img);
         imagedestroy($dst_img);
         return $cacheFile;
     }
 }