How to Rotate and Save Image in PHP?
Hi Dev,
This tutorial will provide an example of save rotated image php. In this article, we will implement a how to rotate and save image in php. Here you will learn rotate and save image php. I’m going to show you about php gd rotate and save image. you will do the following things for rotating image and save php.
If you want to rotate image on upload 90 degrees or 180 degrees in php then this tutorial will help you. we will use imagecreatefrompng(), imagerotate() and imagepng() for rotate png image and save to server. same imagecreatefromjpeg(), imagerotate() and imagejpeg() for jpeg image.
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....
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- PHP JQuery Chosen Ajax Autocomplete Example
- PHP Ajax Drag and Drop Sorting Table Rows Example
- PHP MongoDB CRUD Operation Example
- PHP Ajax Multiple Image Upload with Preview Example
- PHP MySQL Confirmation Before Delete Record using Ajax Example
- PHP MySQL Contact US Form with Validation Example
- PHP Ajax Dependent Dropdown List Example
- Laravel Ajax Image Upload with Validation Example
- PHP Import Excel File into MySQL Database Tutorial
- PHP CRUD Operation Using Ajax and JQuery Example
- PHP JQuery Select2 Ajax Autocomplete Example
- File Upload with Progress Bar using jQuery Ajax and PHP Example
- Mediafire PHP File Uploading and Get Link Example
- Pixel Tracking Code with PHP Example