gpt4 book ai didi

php - 如何旋转图像和保存图像

转载 作者:IT王子 更新时间:2023-10-28 23:58:59 25 4
gpt4 key购买 nike

在我的应用程序中,我在一个 div 中有一个图像,一个按钮。

我想旋转显示的图像并在我使用 jquery 单击按钮时保存旋转后的图像。

我已经使用了代码:

http://code.google.com/p/jquery-rotate/

和 jquery 代码:

$(function() {                                    // doc ready
var rotation = 0; // variable to do rotation with
$("#img").click(function() {
rotation = (rotation + 45) % 360; // the mod 360 probably isn't needed
$("#cropbox").rotate(rotation);
});
});

html代码:

<img src="demo_files/pool.jpg" id="cropbox" />
<input type="button" id="img" name="img" value="click" />

当我使用上面的代码时,有两张图片,一张是旧图片,另一张是旋转后的图片。

这里我想旋转相同的图像并只显示旋转后的图像。并将旋转后的图像保存在目录中。

我如何使用 jquery 来做到这一点?如果使用 jquery 无法实现,那么我如何使用 php/ajax 实现呢?

最佳答案

//define image path
$filename="image.jpg";

// Load the image
$source = imagecreatefromjpeg($filename);

// Rotate
$rotate = imagerotate($source, $degrees, 0);

//and save it on your server...
imagejpeg($rotate, "myNEWimage.jpg");

看看:

imagerotate()

和:

file_put_contents()

关于php - 如何旋转图像和保存图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11259881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com