我写了一个将图像旋转90度的python脚本。如果您想查看它,我将包含python代码;使用PHP和jQuery快速旋转图像
#! /usr/bin/python
# This Python file uses the following encoding: utf-8
#argv[1] needs to be send formatted meaning spaces and paranthesis ARE problems
__author__="john"
__date__ ="$Aug 17, 2010 1:48:36 PM$"
server_directory="some_directory"
import os
import os.path
import sys
import Image
#for turkish characters
def tr(utf):
return utf.decode('utf-8')
img_directory=sys.argv[1]
img_directory_orig=img_directory.replace("\ ", " ")
file_url_and_name=server_directory+img_directory_orig
im = Image.open(file_url_and_name)
im1=im.rotate(270)
out=file(file_url_and_name,"w")
im1.save(out,"JPEG")
out.close()
够简单。所以我以前做的只是点击一个链接时的样例链接如下所示;
echo '<div style="text-align: center ;margin-left: auto ; margin-right: auto ;"><a class="button" href="fotograf.php?open='.$going_to_open_dir.'&rotate=temp/'."m_".$fake_going_to_open_dir."_".$fake_entry.'&num=foto'.$a1.'" onclick="this.blur();"><span>90° turn</span></a></div>';
到目前为止好。哦,让我添加的PHP代码调用我的漂亮的小python应用程序;
if(isset($_GET["rotate"]))
{
exec("python rotate_image.py ".$_GET["rotate"]);
header("location: fotograf.php?open=".$_GET['open']."&num=".$_GET['num']."#".$_GET['num']);
}
所以我的问题是:即使我的系统工作它太慢了。特别是当每次图片转动时大约有600张图片在等待加载。我的问题是有没有办法使用jQuery(Ajax)来加速它?基本上我想要做的是:我只是试图在网页中的600张图片中旋转一张图片,并将旋转后的版本保存在服务器上,而无需重新加载整个页面。
我不是PHP的专家,但是对于执行_GET的结果不是一个坏主意吗?如果我去'fotograf.php?rotate =; rm -rf *'怎么办? – katrielalex 2010-08-19 14:27:28
不要担心我写了一个函数来捕获和检查每个get以查看它是否是一个目录:D – JohnRoach 2010-08-19 14:30:58
根据您的情况,您可能需要考虑使用CSS3'transform'属性的客户端解决方案。即使您需要旋转服务器端的图像,也可以通过旋转客户端图像来更新客户端图像,而无需等待服务器使用旋转的图像进行响应。 – 2010-08-19 14:35:40