rotate() public static method

public static rotate ( integer $color ) : integer
$color integer
return integer
Beispiel #1
0
 /**
  * Rotate an image
  *
  * @param resource     $image   Image GD resource
  * @param int          $angle   -360 < x < 360
  * @param string|array $bgColor Hex color string, array(red, green, blue) or array(red, green, blue, alpha).
  *                              Where red, green, blue - integers 0-255, alpha - integer 0-127
  * @return resource
  * @throws \JBZoo\Utils\Exception
  */
 public static function rotate($image, $angle, $bgColor = '#000000')
 {
     // Perform the rotation
     $angle = Helper::rotate($angle);
     $rgba = Helper::normalizeColor($bgColor);
     $bgColor = imagecolorallocatealpha($image, $rgba[0], $rgba[1], $rgba[2], $rgba[3]);
     $newImage = imagerotate($image, -$angle, $bgColor);
     Helper::addAlpha($newImage);
     return $newImage;
 }
Beispiel #2
0
 /**
  * Add text to an image
  *
  * @param mixed  $image  GD resource
  * @param string $text   Some text to output on image as watermark
  * @param string $fFile  TTF font file path
  * @param array  $params Additional render params
  *
  * @throws Exception
  */
 public static function render($image, $text, $fFile, array $params = array())
 {
     // Set vars
     $params = array_merge(self::$_default, $params);
     $angle = Helper::rotate($params['angle']);
     $position = Helper::position($params['position']);
     $fSize = $params['font-size'];
     $color = $params['color'];
     $offsetX = $params['offset-x'];
     $offsetY = $params['offset-y'];
     $strokeColor = $params['stroke-color'];
     $strokeSize = $params['stroke-size'];
     $strokeSpacing = $params['stroke-spacing'];
     $imageWidth = imagesx($image);
     $imageHeight = imagesy($image);
     $colorArr = self::_getColor($image, $color);
     list($textWidth, $textHeight) = self::_getTextboxSize($fSize, $angle, $fFile, $text);
     list($textX, $textY) = Helper::getInnerCoords($position, array($imageWidth, $imageHeight), array($textWidth, $textHeight), array($offsetX, $offsetY));
     if ($strokeColor && $strokeSize) {
         if (is_array($color) || is_array($strokeColor)) {
             // Multi colored text and/or multi colored stroke
             $strokeColor = self::_getColor($image, $strokeColor);
             $chars = str_split($text, 1);
             foreach ($chars as $key => $char) {
                 if ($key > 0) {
                     $textX = self::_getStrokeX($fSize, $angle, $fFile, $chars, $key, $strokeSpacing, $textX);
                 }
                 // If the next letter is empty, we just move forward to the next letter
                 if ($char === ' ') {
                     continue;
                 }
                 self::_renderStroke($image, $char, array($fFile, $fSize, current($colorArr), $angle), array($textX, $textY), array($strokeSize, current($strokeColor)));
                 // #000 is 0, black will reset the array so we write it this way
                 if (next($colorArr) === false) {
                     reset($colorArr);
                 }
                 // #000 is 0, black will reset the array so we write it this way
                 if (next($strokeColor) === false) {
                     reset($strokeColor);
                 }
             }
         } else {
             $rgba = Helper::normalizeColor($strokeColor);
             $strokeColor = imagecolorallocatealpha($image, $rgba[0], $rgba[1], $rgba[2], $rgba[3]);
             self::_renderStroke($image, $text, array($fFile, $fSize, current($colorArr), $angle), array($textX, $textY), array($strokeSize, $strokeColor));
         }
     } else {
         if (is_array($color)) {
             // Multi colored text
             $chars = str_split($text, 1);
             foreach ($chars as $key => $char) {
                 if ($key > 0) {
                     $textX = self::_getStrokeX($fSize, $angle, $fFile, $chars, $key, $strokeSpacing, $textX);
                 }
                 // If the next letter is empty, we just move forward to the next letter
                 if ($char === ' ') {
                     continue;
                 }
                 $fontInfo = array($fFile, $fSize, current($colorArr), $angle);
                 self::_render($image, $char, $fontInfo, array($textX, $textY));
                 // #000 is 0, black will reset the array so we write it this way
                 if (next($colorArr) === false) {
                     reset($colorArr);
                 }
             }
         } else {
             self::_render($image, $text, array($fFile, $fSize, $colorArr[0], $angle), array($textX, $textY));
         }
     }
 }