Hello all! In this article, we will talk about php gd rotate and save image. let’s discuss about rotating image and save php. if you want to see example of php rotate image and save then you are a right place. This article goes in detailed on php rotate image 90 degrees.
we will simple use imagecreatefrompng(), imagerotate() and imagepng() gd function of php for rotate and save image.
you can see bellow example, i will put one dummy pdf image with "Df7731542705507.png" and write code of rotate, than another image will save with "myUpdateImage.png" name. i make same for jpeg image.
Let's check both example, make sure add one dummy image for testing..
Example for PNG:
<?php
$fileName = "Df7731542705507.png";
$degrees = 90;
$source = imagecreatefrompng($fileName);
$rotate = imagerotate($source, $degrees, 0);
imagepng($rotate, "myUpdateImage.png");
print_r('Image saved successfully.');
?>
Example for JPEG:
<?php
$fileName = "Df7731542705507.jpeg";
$degrees = 90;
$source = imagecreatefromjpeg($fileName);
$rotate = imagerotate($source, $degrees, 0);
imagejpeg($rotate, "myUpdateImage.jpeg");
print_r('Image saved successfully.');
?>
I hope it can help you....
Do you like below Tutorials ?
- PHP Laravel 5.5 - import export data into excel and csv using maatwebsite
- Laravel 7.x and 6.x create custom facade example from scratch
- Node JS - Get Real time online users counter using socket io example
- PHP Laravel 7.x and 6.x - Bootstrap Admin Theme Integration example from scratch
- MySQL Query - How to select records of today to next Sunday ?
- Laravel 7.x and 6.x - username custom validation example
- Laravel 5.5 - Import Extract zip file using chumper/zipper package
- PHP Laravel Set Custom Validation Error Messages Example