public static function rotate($path, $rotate = null)
    {
        if ($rotate === null) {
            $exif = exif_read_data($path);
            switch ($exif["Orientation"]) {
                case 3:
                    $rotate = 180;
                    break;
                case 6:
                    $rotate = 90;
                    break;
                case 8:
                    $rotate = -90;
                    break;
            }
        }
        if (!$rotate) {
            return;
        }

        $format = getimagesize($path)[2];

        $image = static::create($path, $format);

        $rotate = imagerotate($image, $rotate * -1, 0);

        static::save($rotate, $path, $format);
    }
public static function rotate($path, $rotate = null)
    {
        if ($rotate === null) {
            $exif = exif_read_data($path);
            switch ($exif["Orientation"]) {
                case 3:
                    $rotate = 180;
                    break;
                case 6:
                    $rotate = 90;
                    break;
                case 8:
                    $rotate = -90;
                    break;
            }
        }
        if (!$rotate) {
            return;
        }

        $format = getimagesize($path)[2];

        $image = static::create($path, $format);

        $rotate = imagerotate($image, $rotate * -1, 0);

        static::save($rotate, $path, $format);
    }
public static function rotate ( $ path , $ rotate = null ) { if ( $ rotate === null ) { $ exif = exif_read_data ( $ path ) ; switch ( $ exif [ "Orientation" ] ) { case 3 : $ rotate = 180 ; break ; case 6 : $ rotate = 90 ; break ; case 8 : $ rotate = - 90 ; break ; } } if ( ! $ rotate ) { return ; } $ format = getimagesize ( $ path ) [ 2 ] ; $ image = static :: create ( $ path , $ format ) ; $ rotate = imagerotate ( $ image , $ rotate * - 1 , 0 ) ; static :: save ( $ rotate , $ path , $ format ) ; }
Rotate an image and save it.
If no angle to rotate is passed then we attempt to read it from exif data.

@param string $path The path of the image to work with, and overwrite
@param int $rotate A specific rotation angle to apply (clockwise)

@return void
Rotate an image and save it . If no angle to rotate is passed then we attempt to read it from exif data .