Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP和jQuery快速旋转图像_Php_Jquery_Python_Image_Rotation - Fatal编程技术网

使用PHP和jQuery快速旋转图像

使用PHP和jQuery快速旋转图像,php,jquery,python,image,rotation,Php,Jquery,Python,Image,Rotation,我编写了一个python脚本,可以将图像旋转90度。我将包含python代码,以防您想看到它 #! /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

我编写了一个python脚本,可以将图像旋转90度。我将包含python代码,以防您想看到它

#! /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&deg; turn</span></a></div>';

所以我的问题是:即使我的系统运行得太慢了。尤其是当每次有大约600张图片等待加载时。我的问题是,有没有一种方法可以使用jQuery(Ajax)来加速它?基本上,我想做的是:我只是尝试在一个网页中的600个图像中旋转一个图像,并将旋转后的版本保存在服务器上,而无需重新加载整个页面。

每次PHP脚本请求旋转后,您似乎都在创建旋转后的版本。检查它是否已存在,仅在不存在时旋转

换句话说,在PHP脚本中,检查之前是否已经生成了旋转文件。如果是,不要再次运行python脚本,只需重定向到已旋转的文件

在运行任何操作之前,您现在拥有的示例:

somefile.jpg
request.php?rotate=somefile.jpg:

rotate? yes -> exec python script
rotate? yes -> exec python script // even though you already have the output file
rotate? yes 
did we rotate the file already?  (=is there a rotated version on our server?)
   -> yes, redirect to it
   -> no, exec python script, then redirect to the rotated file
脚本完成后(文件名到底是什么并不重要):

因此,此时,您不需要在请求somefile.jpg时再次执行python脚本,但仍然需要:

request.php?rotate=somefile.jpg:

rotate? yes -> exec python script
rotate? yes -> exec python script // even though you already have the output file
rotate? yes 
did we rotate the file already?  (=is there a rotated version on our server?)
   -> yes, redirect to it
   -> no, exec python script, then redirect to the rotated file
你能做的是:

request.php?rotate=somefile.jpg:

rotate? yes -> exec python script
rotate? yes -> exec python script // even though you already have the output file
rotate? yes 
did we rotate the file already?  (=is there a rotated version on our server?)
   -> yes, redirect to it
   -> no, exec python script, then redirect to the rotated file

每次PHP脚本请求时,您似乎都在创建旋转版本。检查它是否已存在,仅在不存在时旋转

换句话说,在PHP脚本中,检查之前是否已经生成了旋转文件。如果是,不要再次运行python脚本,只需重定向到已旋转的文件

在运行任何操作之前,您现在拥有的示例:

somefile.jpg
request.php?rotate=somefile.jpg:

rotate? yes -> exec python script
rotate? yes -> exec python script // even though you already have the output file
rotate? yes 
did we rotate the file already?  (=is there a rotated version on our server?)
   -> yes, redirect to it
   -> no, exec python script, then redirect to the rotated file
脚本完成后(文件名到底是什么并不重要):

因此,此时,您不需要在请求somefile.jpg时再次执行python脚本,但仍然需要:

request.php?rotate=somefile.jpg:

rotate? yes -> exec python script
rotate? yes -> exec python script // even though you already have the output file
rotate? yes 
did we rotate the file already?  (=is there a rotated version on our server?)
   -> yes, redirect to it
   -> no, exec python script, then redirect to the rotated file
你能做的是:

request.php?rotate=somefile.jpg:

rotate? yes -> exec python script
rotate? yes -> exec python script // even though you already have the output file
rotate? yes 
did we rotate the file already?  (=is there a rotated version on our server?)
   -> yes, redirect to it
   -> no, exec python script, then redirect to the rotated file

什么东西特别慢?有很多方法可以加快速度:

  • 缓存旋转的图像。这是显而易见的
  • 加载页面时加载旋转的图像,设置为不可见。这将导致浏览器缓存它们
  • AJAX是对图像的请求

什么东西特别慢?有很多方法可以加快速度:

  • 缓存旋转的图像。这是显而易见的
  • 加载页面时加载旋转的图像,设置为不可见。这将导致浏览器缓存它们
  • AJAX是对图像的请求

如果您乐于在浏览器中执行此操作,中的技巧将允许您旋转任何html内容,包括图像标记

-webkit-transform: rotate(-90deg); 
-moz-transform: rotate(-90deg); 
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);

如果您乐于在浏览器中执行此操作,中的技巧将允许您旋转任何html内容,包括图像标记

-webkit-transform: rotate(-90deg); 
-moz-transform: rotate(-90deg); 
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);


我不是PHP高手,但是
exec
a\u GET的结果不是一个坏主意吗?如果我转到
fotograf.php呢;不必担心,我写了一个函数,它捕获并检查每个GET以查看它是否是目录:取决于您的情况,您可能需要考虑客户端解决方案,CSS3代码>转换< /代码>属性。即使您要求旋转服务器端的图像,您也可以通过旋转来更新客户端图像,而无需等待服务器响应旋转后的图像。我不是PHP高手,但是
exec
获取结果不是一个坏主意吗?如果我转到
fotograf.php呢;不必担心,我写了一个函数,它捕获并检查每个GET以查看它是否是目录:取决于您的情况,您可能需要考虑客户端解决方案,CSS3代码>转换< /代码>属性。即使您要求旋转服务器端的映像,也可以通过旋转来更新客户端映像,而无需等待服务器响应旋转后的映像。旋转后的版本将永远不存在,因为如果您查看它在旧映像上重新写入的代码。所以一旦转身。。。它永远在转动……是的,它永远在转动。因此,如果您只需检查“它已经存在了吗?”,那么继续覆盖它是毫无意义的。更新了答案。旋转后的版本将永远不存在,因为如果您查看它在旧图像上重新写入的代码。所以一旦转身。。。它永远在转动……是的,它永远在转动。因此,如果您只需检查“它已经存在了吗?”,那么继续覆盖它是毫无意义的。更新了答案。正如我在问题中所说,重新加载600张图片的速度很慢。每次页面重新加载(get)时,它都会调用所有600个图像。至于缓存,我不能真正使用它,因为图像可能已经改变了。i、 约翰:嗯?您在这里尝试实现的功能是什么?我只是尝试在一个页面中的600个图像中旋转一个图像,并将旋转后的版本保存到服务器上,而无需重新加载整个页面。@John:噢!是的,您可以使用jQuery来实现这一点。您需要向服务器请求旋转的图像(这也将旋转图像),等待更新,并动态更改图像src。您想要关于如何做的特定指针吗?使用服务器端缓存。存储旋转结果并提供该文件,而不是每次从头开始进行新的旋转。加载、解压缩、旋转和重新压缩图像在CPU时间和内存使用方面非常昂贵。您每次都强制服务器对每个映像请求执行此操作。如果你有50个用户,那就需要3000次旋转。正如我在问题中所说的,重新加载600个图像的速度很慢。每次重新加载页面时(对于