PHP imagerotation旋转到固定位置

时间:2019-02-17 23:07:59

标签: php image-processing gd image-rotation

所以我正在使用imagerotate()使用ajax在按下按钮时将图像旋转90度,效果很好,但我的问题是旋转似乎已固定?

基本上,当我按下按钮时,它将图像逆时针旋转到90度,但是当我再次按下它时,图像不再将其逆时针旋转90度(因此总共变为180度),它只会保持当前的90度学位职位。

$img = imagerotate($img, 90, 0);

这是正常现象还是我做错了什么?如果是这样,我可以使用另一种方法代替吗?

谢谢。

1 个答案:

答案 0 :(得分:2)

您可以使用javascript通过按需增加点击角度来轻松实现点击(fiddle)。

var angle = 90;

$('#flower').click(function() {
  $(this).css({
    '-webkit-transform': 'rotate(' + angle + 'deg)',
    '-moz-transform': 'rotate(' + angle + 'deg)',
    '-o-transform': 'rotate(' + angle + 'deg)',
    '-ms-transform': 'rotate(' + angle + 'deg)'
  });
  angle += 90;
});
#flower {
  position: fixed;
  display: block;
  border:1px  solid grey;
  margin-top: 20px;
  margin-left: 20px;
  height: 100px;
  width: 100px;
  padding: 15px;
  transition: all .5s ease-out;
  -webkit-transition: all .5s ease-out;
  -moz-transition: all .5s ease-out;
  -ms-transition: all .5s ease-out;
  -o-transition: all .5s ease-out;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img src="http://www.rachelgallen.com/images/snowdrops.jpg" id="flower" alt="turning">

您需要将单独的角度值传递到imagerotate php函数中,因此您可以使用JavaScript或将旋转图像设置为源图像,以使用php method进行第二次单击来旋转。

希望这会有所帮助

相关问题