PHP图像旋转旋转到固定位置

问题描述 投票:1回答:1

所以我使用imagerotate()在按下按钮时使用ajax将图像旋转90度,这是正常工作但我的问题是旋转似乎是固定的?

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

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

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

谢谢。

php image-processing gd image-rotation
1个回答
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在第二次单击时旋转。

希望这可以帮助

© www.soinside.com 2019 - 2024. All rights reserved.