direction() public static method

public static direction ( string $direction ) : string
$direction string
return string
Beispiel #1
0
 /**
  * Flip an image horizontally or vertically
  *
  * @param mixed  $image GD resource
  * @param string $dir   Direction of fliping - x|y|yx|xy
  * @return resource
  */
 public static function flip($image, $dir)
 {
     $dir = Helper::direction($dir);
     $width = imagesx($image);
     $height = imagesy($image);
     $newImage = imagecreatetruecolor($width, $height);
     Helper::addAlpha($newImage);
     if ($dir === 'y') {
         for ($y = 0; $y < $height; $y++) {
             imagecopy($newImage, $image, 0, $y, 0, $height - $y - 1, $width, 1);
         }
     } elseif ($dir === 'x') {
         for ($x = 0; $x < $width; $x++) {
             imagecopy($newImage, $image, $x, 0, $width - $x - 1, 0, 1, $height);
         }
     } elseif ($dir === 'xy' || $dir === 'yx') {
         $newImage = self::flip($image, 'x');
         $newImage = self::flip($newImage, 'y');
     }
     return $newImage;
 }