Jump to content

[SOLVED] image rotate problem


Harley1979

Recommended Posts

I am using this code to rotate an image 90 degrees counterclockwise and clockwise. Each time the links are clicked, $i should increment/decrement, returning a result from the array which is used in the imagerotate line.

 

<?php

$getImage = "../directory/test.jpg";
$src = imagecreatefromjpeg($getImage);

&angle[1] = 0.0;
&angle[2] = 90.0;
&angle[3] = 180.0;
&angle[4] = 270.0;

if (empty($i)){
$i = 1;
}

if ($i > 4){$i = 1}
if ($i < 1){$i = 4}

$rotate = imagerotate($src, $angle[$i], 0);
imagejpeg($rotate, "../directory/test.jpg", 100)

?>

<a href="?i=<?php $i + 1 ?>">Rotate clockwise</a>
<a href="?i=<?php $i - 1 ?>">Rotate counter clockwise</a>

 

I just can't seem to get this to work properly, any help would be really appreciated.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/65795-solved-image-rotate-problem/
Share on other sites

try this out

 

<?php

$getImage = "../directory/test.jpg";
$src = imagecreatefromjpeg($getImage);

$angle[1] = 0.0;
$angle[2] = 90.0;
$angle[3] = 180.0;
$angle[4] = 270.0;

if (empty($i)){
$i = 1;
}

if ($i > 4){$i = 1}
if ($i < 1){$i = 4}

$rotate = imagerotate($src, $angle[$i], 0);
imagejpeg($rotate, "../directory/test.jpg", 100)

?>

<a href="?i=<?php echo ($i + 1); ?>">Rotate clockwise</a>
<a href="?i=<?php echo ($i - 1); ?>">Rotate counter clockwise</a>

sorry missed one line

 

try this

 

<?php

$getImage = "../directory/test.jpg";
$src = imagecreatefromjpeg($getImage);

$angle[1] = 0.0;
$angle[2] = 90.0;
$angle[3] = 180.0;
$angle[4] = 270.0;

$i = $_GET['i'];

if (!isset($i) || $i == ''){
$i = 1;
}

if ($i > 4){$i = 1}
if ($i < 1){$i = 4}

$rotate = imagerotate($src, $angle[$i], 0);
imagejpeg($rotate, "../directory/test.jpg", 100)

?>

<a href="?i=<?php echo ($i + 1); ?>">Rotate clockwise</a>
<a href="?i=<?php echo ($i - 1); ?>">Rotate counter clockwise</a>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.