|
-
Nov 15th, 2007, 12:52 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Reverse Image
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.
-
Nov 15th, 2007, 01:16 AM
#2
Re: Reverse Image
Reverse how? Flip horizontally or vertically, or invert colours?
-
Nov 15th, 2007, 02:50 AM
#3
Thread Starter
Hyperactive Member
Re: Reverse Image
Reverse means 180 degree reverse.
-
Nov 15th, 2007, 02:54 AM
#4
Re: Reverse Image
Rotate, you mean.
There's a sample of exactly that on this page.
http://php.about.com/od/gdlibrary/a/rotate_image_gd.htm
-
Nov 16th, 2007, 06:20 AM
#5
Thread Starter
Hyperactive Member
Re: Reverse Image
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.
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>
Thanks a lot again.
-
Nov 16th, 2007, 09:16 AM
#6
Hyperactive Member
Re: Reverse Image
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);
?>
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>
Should work.
» Twitter: @rudi_visser : Website: www.rudiv.se «
If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.
-
Dec 13th, 2007, 01:41 AM
#7
Thread Starter
Hyperactive Member
Re: Reverse Image
Thanks a lot RudiVisser. This code is working fine.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|