批量调整大小 50+ ColdFusion 中的大图像
我正在尝试升级一个照片库系统,我们必须能够获取包含 50-100 个大(~500K-1MB)图像的文件夹,并为每个图像批量处理缩略图、中分辨率和高分辨率版本(并添加将每个记录记录到数据库中)。
我编写了一个
来实现这一点。它适用于包含较小图像的小文件夹,但是包含大图像的较大文件夹将产生严重的性能问题,并在仅完成我抛出的 50 个或更多图像中的大约 10 个后引发随机错误(超时或文件权限问题)。
我的问题:如何完成如此密集的任务,同时最大限度地减少对整个服务器的性能影响?单独使用 ColdFusion 是否可行,还是我需要研究其他服务器插件? (我在这方面没有任何经验。)
更新:由于我的共享托管限制,我目前将注意力转移到上传之前的客户端调整大小 (Flash),因此服务器仅具有上传/移动并创建数据库记录。但是,我需要将原始图像的大小调整为每个缩略图/中/大版本并将其全部上传。现在我只看到上传一张调整大小的图像的示例,但我会尝试使用源。
更新 2: 我看过一些非常酷的演示,它们展示了使用 HTML5 调整图像大小,我将尝试一下。我会发回任何结果。
I'm trying to upgrade a photo gallery system we have to be able to take a folder of 50-100 large (~500K-1MB) images and batch process a thumbnail, medium, and high-resolution version for each (and add a record for each to a database).
I wrote a <cffunction>
that does exactly that. It works well with a small folder of smaller images, however a larger folder of large images will generate serious performance issues and throw random errors (timeouts or file permission issues) after only completing about 10 of the 50 or more I throw at it.
My question: how do I accomplish something this intensive while minimizing the performance affect on the entire server? Is it even possible with ColdFusion alone, or do I need to look into other server plugins? (I don't have any experience in this area.)
Update: With my shared hosting limitations, I'm currently redirecting my attention to client-side resizing (Flash) before uploading so the server only has to upload/move and create the db records. However, I would need something that resizes the original images into a thumb/medium/large version for each and uploads them all. Right now I'm only seeing examples that upload one resized image, but I'll try playing around with the sources.
Update 2: I've seen some pretty cool demos that showcase resizing images using the HTML5 <canvas>
and I'm going to try my hand at that. I'll post back any results.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为你最好的选择是使用异步网关:
http://www.coldfusionjedi.com/index.cfm/2006/9/7/Using-ColdFusions-Asynchronous-Gateway
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef /index.html
I think your best bet is to use an Asycronous Gateway:
http://www.coldfusionjedi.com/index.cfm/2006/9/7/Using-ColdFusions-Asynchronous-Gateway
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/index.html
与 ImageMagik 会击败使用
在速度和效率方面。http://www.imagemagick.org/www/mogrify.html
<cfexecute>
with ImageMagik would beat resizing with<cfimage>
in terms of speed and efficiency.http://www.imagemagick.org/www/mogrify.html
好吧,也许是异步网关、JVM 调整的组合,可能添加更多 RAM 或将图像处理拆分到不运行主应用程序的单独物理服务器上。
Well, maybe a combination of Async Gateways, JVM tuning, possibly adding more RAM or splitting image processing onto a separate physical server that does not run the main application.
问题是否在于您试图在一个过程中完成这一切?
一些建议是:-
使用 cfthread,它允许您并行运行相同的进程,每个进程都可以一次处理少量图像。说你在共享主机上,但我不确定你是否可以使用它。您必须与提供商核实。
另一种选择可能是设置每分钟左右运行一次的计划任务。它需要 XX 数量的图像,完成工作然后停止。下一个计划将选取下一批,依此类推...
这将减少流程密集度,但我不确定如果他们期望返回某种结果,您将如何管理用户交互。您还需要考虑时间安排,即如果之前的计划任务尚未完成怎么办。
詹姆斯
Is the issue maybe more that you're trying to do this all in one process?
A couple of suggestions would be:-
Use cfthread which would allow you to run the same process in parallel, each of which could handle a small amount of your imagery at one time. Saying that you're on a shared host though I'm not sure if that's going to be available to you. You'd have to check with the provider.
Another option could be to setup a scheduled task that runs every minute or so. That takes in XX amount of imagery, does the work and then stops. The next schedule would pick up the next batch and so on...
That would be less process intensive but I'm not sure how you would manage user interaction if they're expecting some kind of result back. You'd also need to take into account with timings i.e. what if the previous scheduled task hadn't finished.
James