Esempio n. 1
0
function imageTtfBBox_fixed($size, $angle, $fontfile, $text)
{
    // Вычисляем размер при НУЛЕВОМ угле поворота.
    $horiz = imageTtfBBox($size, 0, $fontfile, $text);
    // Вычисляим синус и косинус угла поворота.
    $cos = cos(deg2rad($angle));
    $sin = sin(deg2rad($angle));
    $box = [];
    // Выполняем поворот каждой координаты.
    for ($i = 0; $i < 7; $i += 2) {
        list($x, $y) = [$horiz[$i], $horiz[$i + 1]];
        $box[$i] = round($x * $cos + $y * $sin);
        $box[$i + 1] = round($y * $cos - $x * $sin);
    }
    return $box;
}
Esempio n. 2
0
 /**
  * Returns boundings of text depending on the available font extension
  * 
  * @param float $size Textsize
  * @param ezcGraphFontOptions $font Font
  * @param string $text Text
  * @return ezcGraphBoundings Boundings of text
  */
 protected function getTextBoundings($size, ezcGraphFontOptions $font, $text)
 {
     switch ($font->type) {
         case ezcGraph::PS_FONT:
             if (!isset($this->psFontRessources[$font->path])) {
                 $this->psFontRessources[$font->path] = imagePsLoadFont($font->path);
             }
             $boundings = imagePsBBox($text, $this->psFontRessources[$font->path], $size);
             return new ezcGraphBoundings($boundings[0], $boundings[1], $boundings[2], $boundings[3]);
         case ezcGraph::TTF_FONT:
             switch (true) {
                 case ezcBaseFeatures::hasFunction('imageftbbox') && !$this->options->forceNativeTTF:
                     $boundings = imageFtBBox($size, 0, $font->path, $text);
                     return new ezcGraphBoundings($boundings[0], $boundings[1], $boundings[4], $boundings[5]);
                 case ezcBaseFeatures::hasFunction('imagettfbbox'):
                     $boundings = imageTtfBBox($size, 0, $font->path, $text);
                     return new ezcGraphBoundings($boundings[0], $boundings[1], $boundings[4], $boundings[5]);
             }
             break;
     }
 }
 function GenerateThumbnail($src, $dst, $mw, $mh, $alwaysResize = false)
 {
     $size = @getImageSize($src);
     if (!$size || !($size[2] == 1 || $size[2] == 2 || $size[2] == 3)) {
         return false;
     }
     switch ($size[2]) {
         case 1:
             $type = 'gif';
             break;
         case 2:
             $type = 'jpeg';
             break;
         case 3:
             $type = 'png';
             break;
     }
     if (isset($type)) {
         switch ($type) {
             case 'jpeg':
                 $sim = imageCreateFromJPEG($src);
                 break;
             case 'gif':
                 $sim = imageCreateFromGIF($src);
                 break;
             case 'png':
                 $sim = imageCreateFromPNG($src);
                 break;
         }
         if ($mw <= 0 || $mh <= 0) {
             $tw = $size[0];
             $th = $size[1];
         } elseif ($size[0] > $mw || $size[1] > $mh || $alwaysResize) {
             $ratio = $size[0] > $size[1] ? $size[0] / $mw : $size[1] / $mh;
             $tw = $size[0] / $ratio;
             $th = $size[1] / $ratio;
         } else {
             $tw = $size[0];
             $th = $size[1];
         }
         $text = $size[0] . 'x' . $size[1] . ' - ' . intval(filesize($src) / 1024) . 'Kb';
         $font = BASE_PATH . 'incl/serifan.ttf';
         $fontsize = 12 + 1;
         $fontangle = 0;
         do {
             $fontsize--;
             $bounds = imageTtfBBox($fontsize, $fontangle, $font, $text);
         } while ($fontsize > 6 && abs($bounds[0] - $bounds[2]) > $tw);
         $tha = 6 + abs($bounds[1] - $bounds[7]);
         $thumb = imageCreateTrueColor($tw, $th + $tha);
         imageCopyResampled($thumb, $sim, 0, 0, 0, 0, $tw, $th, $size[0], $size[1]);
         $th += $tha;
         $black = imageColorAllocate($thumb, 0, 0, 0);
         $white = imageColorAllocate($thumb, 255, 255, 255);
         $GLOBALS['image_orig_width'] = $size[0];
         $GLOBALS['image_orig_height'] = $size[1];
         $GLOBALS['image_thumb_width'] = $tw;
         $GLOBALS['image_thumb_height'] = $th;
         imageFilledRectangle($thumb, 0, $th - $tha, $tw - 1, $th - 1, $black);
         imageTtfText($thumb, $fontsize, $fontangle, $tw / 2 - $bounds[2] / 2, $th - 4 - $bounds[3], $white, $font, $text);
         imageRectangle($thumb, 0, 0, $tw - 1, $th - 1, $black);
         switch ($type) {
             case 'jpeg':
                 imageJPEG($thumb, $dst);
                 break;
             case 'gif':
                 imageGIF($thumb, $dst);
                 break;
             case 'png':
                 imagePNG($thumb, $dst);
                 break;
         }
         return true;
     }
     return false;
 }