How to rotate and save image in php?

How to rotate and save image in php?

In this post we will give you information about How to rotate and save image in php?. Hear we will give you detail about How to rotate and save image in php?And how to use it also give you demo for it if it is necessary.

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:

Also see:File Upload using Vue js Axios PHP

<?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….

Hope this code and post will helped you for implement How to rotate and save image in php?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

4  +  2  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US