Hi,
Is it possible to reverse picture using PHP ? Please help me solve it out. I have a picture and I like to reverse the picture on the basis of some condition runtime from the PHP script.
Thanks a lot in advance.
Printable View
Hi,
Is it possible to reverse picture using PHP ? Please help me solve it out. I have a picture and I like to reverse the picture on the basis of some condition runtime from the PHP script.
Thanks a lot in advance.
Reverse how? Flip horizontally or vertically, or invert colours?
Reverse means 180 degree reverse.
Rotate, you mean.
There's a sample of exactly that on this page.
http://php.about.com/od/gdlibrary/a/rotate_image_gd.htm
Thanks penagate. This code is working fine. But I faced trouble by use the code in the following manner.
I am trying to use it as a function. I am getting error regarding header information. But I do not understand where I have done the mess. Please help me.
Thanks a lot again.PHP Code:
<?php
function Image_Rotate($path)
{
// The file you are rotating
$temp="Test";
$image=$path.".jpg";
//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
$source = imagecreatefromjpeg($image) ;
// Rotates the image
$rotate = imagerotate($source, $degrees, 0) ;
// Outputs a jpg image, you could change this to gif or png if needed
return imagejpeg($rotate) ;
}
?>
<html>
<head>
<title>Image Rotate</title>
</head>
<body>
<form name="f" method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
<table border="1" width="100%">
<tr>
<td width="50%" align="center">
<?php
$temp="Test";
$pic="pics/".strtolower($temp);
echo "<img src='{$pic}.jpg' type='image'>";
?>
</td>
<td align="center">
<?php
$temp="Test";
$pic="pics/".strtolower($temp);
$pic=Image_Rotate($pic);
echo "<img src='{$pic}.jpg' type='image'>";
?>
</td>
</tr>
</table>
</form>
</body>
</html>
You are sending content to the browser, THEN calling the function, you can't do that.
That code wouldn't work anyway. You need to put it into a seperate page, and I would suggest that you make it operate off of $_GET.
Here's an example (using your code so sorry if it doesn't work) of what I mean:
PHP Code:<?php
// image.php
$image=$_GET['image'];
//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
$source = imagecreatefromjpeg($image) ;
// Rotates the image
$rotate = imagerotate($source, $degrees, 0) ;
// Outputs a jpg image, you could change this to gif or png if needed
imagejpeg($rotate);
?>
Should work.PHP Code:<html>
<head>
<title>Image Rotate</title>
</head>
<body>
<form name="f" method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
<table border="1" width="100%">
<tr>
<td width="50%" align="center">
<img src="pics/whatever.jpg" alt="Non-rotated" />
</td>
<td align="center">
<img src="image.php?image=pics/whatever.jpg" alt="Rotated" />
</td>
</tr>
</table>
</form>
</body>
</html>
Thanks a lot RudiVisser. This code is working fine.