dongxiangchan0743 2014-01-13 22:04
浏览 161
已采纳

通过PHP使用ImageMagick创建一个大型精灵消耗100%的CPU

So I've this:

exec("cd $upload_directory && convert \\( +append -limit memory 1 -limit map 1 *.jpg \\) -strip -trim -interlace Plane -quality 60 output.jpg

The workflow is:

  • User uploads *.zip file, containing about 30 pictures 2048x1152 each
  • Application unzips zip file
  • Application takes the pictures and makes a large sprite out of all of them
  • Application then redirects to a different page for processing.

Now the problems is with making the large sprite. It consumes 100% CPU (according to top on the server), it fails when there are many images. Also the process outputs Killed without any further error message.

Now, I'm sure I can solve this by throwing more muscle on the server, but I'm having the feeling that the one I have isn't the most efficient.

What can I try to mitigate the problem?

  • 写回答

1条回答 默认 最新

  • dongzhao4036 2014-01-20 19:18
    关注

    You kind-of answered your own question. You are doing something really intensive. The expected outcome is that CPU usage will shoot-up. Unzipping takes memory and cpu. Creating massive images takes IO, CPU, and Memory. If you ever used Photoshop, youll notice that your systems memory and cpu always shoots-up. Dealing with images is no simple task.

    If you want to handle large images using the current method, then you need a stronger server. There is no magic parameter that will make the process use less memory. If you have a 32MB image, its going to take a lot of memory to read it before you can even try to reduce its size.

    Hope that helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等