简体   繁体   English

图片上传和处理,是服务器端还是客户端?

[英]Image upload and processing, server side or client side?

My site requires squared images. 我的网站要求图像平方。 At the moment I have a very basic image upload facility. 目前,我有一个非常基本的图像上传工具。 Images are uploaded and the resized and squared in PHP on the server. 在服务器上用PHP上传图像并调整大小并平方。 This is causing the following problems: - It uses a lot of server resources - Images are often imperfectly squared - There is no indication of progress to the user, particularly a problem when they try to upload large images 这会导致以下问题:-使用大量服务器资源-图像通常不完美地平方-用户没有进度的迹象,尤其是当他们尝试上传大图像时出现问题

I'm now starting to look at implanting an all new image upload page. 我现在开始考虑植入一个全新的图像上传页面。 What would you recommend, keep processing in PHP. 您会推荐什么,继续使用PHP处理。 I thought maybe i could do it client side (we use jQuery), are there any good existing libraries? 我想也许我可以在客户端(我们使用jQuery)做到这一点,是否有任何好的现有库? Is doing this client side a good idea. 做这个客户端是个好主意。 What is a good PHP/javascript workflow? 什么是好的PHP / javascript工作流程?

Sticking with tried/true server side solutions, try using ImageMagick to do your resize, instead of php's built in image processing. 坚持使用可靠的服务器端解决方案,尝试使用ImageMagick进行调整大小,而不是使用PHP的内置图像处理功能。

It works much better in our experience. 根据我们的经验,它的效果要好得多。

You could try to use a jQuery cropping plugin like JCrop which supports ratio locking to ensure squared images. 您可以尝试使用JCrop之类的jQuery裁剪插件,该插件支持比率锁定以确保图像平方。

Please remember that nothing on the client side is 100% secure so any validation also has to be duplicated on the server side. 请记住,客户端没有什么是100%安全的,因此任何验证也必须在服务器端进行重复。 This may mean checking the width/height of the image and cropping again in PHP if necessary. 这可能意味着检查图像的宽度/高度,并在必要时在PHP中再次进行裁剪。

if you are talking about changing the actual image data, you can not rely entirely on a client side solution, not all browsers will have the functionality you need. 如果您要谈论更改实际的图像数据,则不能完全依靠客户端解决方案,不是所有的浏览器都具有所需的功能。 You can fall back to Flash for browsers that can't do this in js, but that starts to get gross really quick as you'll need two uploaders. 对于无法在js中执行此操作的浏览器,您可以使用Flash,但是由于需要两个上载器,因此开始变得非常快。

I'd recommend doing it in browsers that support it, and relying on a server side solution for those that don't. 我建议在支持该功能的浏览器中执行此操作,对于不支持该功能的浏览器,请依靠服务器端解决方案。 you can spread your resources out by processing them in a queue rather than immediately when uploaded if its still an issue. 您可以通过在队列中处理资源来分散资源,而不是在上传时立即解决(如果仍然存在问题)。

Canvas is a great way to do this on modern browsers, you don't need a plugin. Canvas是在现代浏览器中执行此操作的好方法,您不需要插件。 Look here at how to grab image data for uploading. 在这里查看如何获取要上传的图像数据。

https://developer.mozilla.org/En/HTML/Canvas/Pixel_manipulation_with_canvas https://developer.mozilla.org/En/HTML/Canvas/Pixel_manipulation_with_canvas

Here is a lib: http://www.nihilogic.dk/labs/canvas2image/ 这是一个库: http : //www.nihilogic.dk/labs/canvas2image/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM