You can achieve this by using any image Processing and Generation libraries like Imagick/ GD
Example with GD
You have to use imagerotate function in this cause
Code sample to rotate an image to 180 degree using GD.
$sourceImage = imagecreatefromjpeg('test-design-image.jpg');
$rotateImage = imagerotate($source, 180, 0);
$saveImage = imagejpeg($rotate, 'test-design-rotated.jpg');
imagedestroy($sourceImage);
imagedestroy($rotateImage);
You can use Imagick library also if this library is available with your php.
Example with Imagick::rotateImage
$sourceImage = new Imagick('test-design-image.jpg');
$sourceImage->rotateImage(new \ImagickPixel(), 180);
$sourceImage->writeImage ("test-design-rotated.jpg"); // if it fails, use the
following method
file_put_contents ("test-design-rotated.jpg", $sourceImage);
Imagick may not installed by default with most php and wampp/lampp/xampp installations. You can check with phpinfo() to verify that Imagick is installed or not.