Exemplo n.º 1
0
 static function createForText($text, &$font, $widthAdjustment, $heightAdjustment, $angle, $absoluteWidth = false, $absoluteHeight = false)
 {
     $Return = false;
     if (!$font instanceof eZImageFont) {
         return $Return;
     }
     if (!function_exists('ImageTTFBBox')) {
         eZDebug::writeError('ImageTTFBBox function not in PHP, check PHP compilation', 'ezimagetextlayer.php');
         return $Return;
     }
     $bbox = ImageTTFBBox($font->pointSize(), $angle, $font->realFile(), $text);
     if (!$bbox) {
         return $Return;
     }
     $xmin = min($bbox[0], $bbox[2], $bbox[4], $bbox[6]);
     $xmax = max($bbox[0], $bbox[2], $bbox[4], $bbox[6]);
     $ymin = min($bbox[1], $bbox[3], $bbox[5], $bbox[7]);
     $ymax = max($bbox[1], $bbox[3], $bbox[5], $bbox[7]);
     $width = abs($xmax - $xmin);
     $height = abs($ymax - $ymin);
     $width += $widthAdjustment;
     $height += $heightAdjustment;
     if ($absoluteWidth !== false) {
         $width = $absoluteWidth;
     }
     if ($absoluteHeight !== false) {
         $height = $absoluteHeight;
     }
     $layer = new eZImageTextLayer(null, null, $width, $height, $font, $bbox, $text, $angle);
     $layer->create($width, $height, null);
     return $layer;
 }
 function modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$inputValue, $namedParameters, $placement)
 {
     if (!$this->ImageGDSupported) {
         eZDebug::writeError("{$operatorName} cannot be used since the following ImageGD functions are missing: " . implode(', ', $this->MissingGDFunctions));
         return;
     }
     if ($operatorName == 'texttoimage') {
         $class = $namedParameters['class'];
         $family = $this->Family;
         $size = $this->PointSize;
         $angle = $this->Angle;
         $xadj = $this->XAdjust;
         $yadj = $this->YAdjust;
         $wadj = $this->WAdjust;
         $hadj = $this->HAdjust;
         $usecache = $this->UseCache;
         $bgcol = $this->color("bgcolor");
         $textcol = $this->color("textcolor");
         $ini = eZINI::instance('texttoimage.ini');
         $family = $ini->variable('DefaultSettings', 'Family');
         $size = $ini->variable('DefaultSettings', 'PointSize');
         $angle = $ini->variable('DefaultSettings', 'Angle');
         $xadj = $ini->variable('DefaultSettings', 'XAdjustment');
         $yadj = $ini->variable('DefaultSettings', 'YAdjustment');
         $wadj = $ini->variable('DefaultSettings', 'WidthAdjustment');
         $hadj = $ini->variable('DefaultSettings', 'HeightAdjustment');
         $bgcol = $this->decodeColor($ini->variable('DefaultSettings', 'BackgroundColor'));
         $textcol = $this->decodeColor($ini->variable('DefaultSettings', 'TextColor'));
         $absoluteWidth = false;
         $absoluteHeight = false;
         if ($ini->hasVariable($class, 'Family')) {
             $family = $ini->variable($class, 'Family');
         }
         if ($ini->hasVariable($class, 'PointSize')) {
             $size = $ini->variable($class, 'PointSize');
         }
         if ($ini->hasVariable($class, 'Angle')) {
             $angle = $ini->variable($class, 'Angle');
         }
         if ($ini->hasVariable($class, 'XAdjustment')) {
             $xadj = $ini->variable($class, 'XAdjustment');
         }
         if ($ini->hasVariable($class, 'YAdjustment')) {
             $yadj = $ini->variable($class, 'YAdjustment');
         }
         if ($ini->hasVariable($class, 'WidthAdjustment')) {
             $wadj = $ini->variable($class, 'WidthAdjustment');
         }
         if ($ini->hasVariable($class, 'HeightAdjustment')) {
             $hadj = $ini->variable($class, 'HeightAdjustment');
         }
         if ($ini->hasVariable($class, 'BackgroundColor')) {
             $bgcol = $this->decodeColor($ini->variable($class, 'BackgroundColor'));
         }
         if ($ini->hasVariable($class, 'TextColor')) {
             $textcol = $this->decodeColor($ini->variable($class, 'TextColor'));
         }
         if ($ini->hasVariable($class, 'AbsoluteWidth')) {
             $absoluteWidth = $ini->variable($class, 'AbsoluteWidth');
         }
         if ($ini->hasVariable($class, 'AbsoluteHeight')) {
             $absoluteHeight = $ini->variable($class, 'AbsoluteHeight');
         }
         if ($namedParameters['family'] !== null) {
             $family = $namedParameters["family"];
         }
         if ($namedParameters["pointsize"] !== null) {
             $size = $namedParameters["pointsize"];
         }
         if ($namedParameters["angle"] !== null) {
             $angle = $namedParameters["angle"];
         }
         if ($namedParameters["x"] !== null) {
             $xadj = $namedParameters["x"];
         }
         if ($namedParameters["y"] !== null) {
             $yadj = $namedParameters["y"];
         }
         if ($namedParameters["w"] !== null) {
             $wadj = $namedParameters["w"];
         }
         if ($namedParameters["h"] !== null) {
             $hadj = $namedParameters["h"];
         }
         if ($namedParameters["usecache"] !== null) {
             $usecache = $namedParameters["usecache"];
         }
         if ($namedParameters["bgcolor"] !== null) {
             $bgcol = $this->decodeColor($namedParameters["bgcolor"]);
         }
         if ($namedParameters["textcolor"] !== null) {
             $textcol = $this->decodeColor($namedParameters["textcolor"]);
         }
         $storeImage = $namedParameters["storeimage"];
         $fontDir = false;
         foreach ($this->FontDir as $fontPath) {
             if (eZImageFont::exists($family, $fontPath)) {
                 $fontDir = $fontPath;
                 break;
             }
         }
         if (!$fontDir) {
             return;
         }
         $font = new eZImageFont($family, $size, $fontDir, $xadj, $yadj);
         if ($bgcol === null) {
             $bgcol = $this->color("bgcolor");
         }
         if (!is_array($bgcol) or count($bgcol) < 3) {
             $bgcol = array(255, 255, 255);
         }
         if ($textcol === null) {
             $textcol = $this->color("textcolor");
         }
         if (!is_array($textcol) or count($textcol) < 3) {
             $textcol = array(0, 0, 0);
         }
         $alternativeText = htmlspecialchars($inputValue);
         if (is_string($usecache)) {
             $md5Text = $usecache;
         } else {
             $md5Text = md5($inputValue . $family . $size . $angle . $xadj . $yadj . $wadj . $hadj . $absoluteWidth . $absoluteHeight . implode(",", $bgcol) . implode(",", $textcol));
         }
         if (is_string($usecache) or !$usecache or !$this->hasImage($this->CacheDir, 'imagetext', $md5Text, $alternativeText, $this->StoreAs)) {
             $layer = eZImageTextLayer::createForText($inputValue, $font, $wadj, $hadj, $angle, $absoluteWidth, $absoluteHeight);
             if (!$layer) {
                 $tpl->error($operatorName, "Could not open font \"{$family}\", no image created", $placement);
                 return;
             }
             $layer->allocateColor('bgcol', $bgcol[0], $bgcol[1], $bgcol[2]);
             $layer->allocateColor('textcol', $textcol[0], $textcol[1], $textcol[2]);
             $layer->setTextColor('textcol');
             if ($storeImage) {
                 $this->storeImage($layer, $this->CacheDir, 'imagetext', $md5Text, $alternativeText, $this->StoreAs);
             }
             $layer->destroy();
         } else {
             $layer = $this->loadImage($this->CacheDir, 'imagetext', $md5Text, $alternativeText, $this->StoreAs);
         }
         $layer->setAlternativeText($alternativeText);
         $inputValue = $layer;
     } else {
         if ($operatorName == 'image') {
             $useCache = $this->UseCache;
             $image = new eZImageObject();
             $md5Input = "image\n";
             $alternativeText = '';
             $this->readImageParameters($tpl, $image, $operatorParameters, $rootNamespace, $currentNamespace, $md5Input, $alternativeText, $placement);
             $image->setAlternativeText($alternativeText);
             $md5Text = md5($md5Input);
             if (!$useCache or !$this->hasImage($this->CacheDir, 'imageobject', $md5Text, $alternativeText, $this->StoreAs)) {
                 $this->storeImage($image, $this->CacheDir, 'imageobject', $md5Text, $alternativeText, $this->StoreAs);
                 $image->destroy();
                 $inputValue = $image;
             } else {
                 $this->setLoadImage($image, $this->CacheDir, 'imageobject', $md5Text, $alternativeText, $this->StoreAs);
                 $image->load();
                 $inputValue = $image;
             }
         } else {
             if ($operatorName == 'imagefile') {
                 $file =& $namedParameters['filename'];
                 $options =& $namedParameters['options'];
                 $dir = '';
                 if (preg_match("#^(.+)/([^/]+)\$#", $file, $matches)) {
                     $dir = $matches[1];
                     $file = $matches[2];
                 }
                 $layer = eZImageLayer::createForFile($file, $dir);
                 $alternativeText = $file;
                 if (preg_match("#(.+)\\.([^.]+)\$#", $file, $matches)) {
                     $alternativeText = $matches[1];
                 }
                 $layer->setAlternativeText($alternativeText);
                 $inputValue = $layer;
             }
         }
     }
 }