JBZoo\Image\Filter::flip PHP Метод

flip() публичный статический Метод

Flip an image horizontally or vertically
public static flip ( mixed $image, string $dir ) : resource
$image mixed GD resource
$dir string Direction of fliping - x|y|yx|xy
Результат 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;
    }