How to rotate image in php?

I have a function that generates text that matches the bottom of the circle. Since I don’t know another way that I can make the function fit the top of the circle so that it appears in front of me, I want to rotate the image, write on it, rotate it back and write it again. How can I do this without changing the image name?

I tried something like this:

<?php function create_image() { $im = @imagecreate(140, 140)or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, 255, 255, 255); imageellipse ( $im , $cx , $cy , $size*2 , $size*2 , $black ); write($im,$cx,$cy,$size,$s,$e,$black,$text1,$font,$size,$pad); imagerotate($im, 180,0); write($im,$cx,$cy,$size,$s,$e,$black,$text2,$font,$size,$pad); imagerotate($im, 180,0); imagepng($im,"image.png"); imagedestroy($im); } ?> <?php create_image(); print "<img src=image.png?".date("U").">"; ?> 

But that will not work. He does not rotate the image.

Can you help me?

Thanx!

+4
source share
3 answers

Not sure why you need to rotate twice .. but this is what your code should look like

 function create_image($img) { $im = @imagecreatefrompng($img) or die("Cannot Initialize new GD image stream"); $rotate = imagerotate($im, 180, 0); imagepng($rotate); imagedestroy($rotate); imagedestroy($im); } header('Content-Type: image/png'); $image = "a.png"; create_image($image); 
+3
source

Why don't you just take a normal image and add CSS to it?

CSS

 .yourImage { -webkit-transform: rotate(-90deg); -moz-transform: rotate(-90deg); filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3); } 

HTML

 <img class="yourImage" src="originalImage.jpg"> 
+4
source

You can do this easily using the php rotation function. Here is a simple code

 <?php $image = 'test.jpg'; // The file you are rotating //How many degrees you wish to rotate $degrees = 180; // This sets the image type to .jpg but can be changed to png or gif header('Content-type: image/jpeg') ; // Create the canvas $src = $image; $system = explode(".", $src); if (preg_match("/jpg|jpeg/", $system[1])) { $src_img=imagecreatefromjpeg($src); } if (preg_match("/png/", $system[1])) { $src_img = imagecreatefrompng($src); } if (preg_match("/gif/", $system[1])) { $src_img = imagecreatefromgif($src); } // Rotates the image $rotate = imagerotate($src_img, $degrees, 0) ; // Outputs a jpg image, you could change this to gif or png if needed if (preg_match("/png/", $system[1])) { imagepng($rotate,$image); } else if (preg_match("/gif/", $system[1])) { imagegif($rotate, $image); } else { imagejpeg($rotate, $image); } imagedestroy($rotate); imagedestroy($src_img); ?> 
+2
source

Source: https://habr.com/ru/post/1445247/


All Articles