Jump to content

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.