Imagick 处理器能力不够?

发布于 2024-09-29 22:33:06 字数 2024 浏览 0 评论 0原文

我正在尝试使用以下配置在 VDS 上制作裁剪动画 gif:

~800MHz 和 256 RAM

但它不起作用。它只是消耗内存和处理器,大约一分钟后就没有返回任何响应。

http://i192.photobucket.com/albums/z228/Somebi/no -responce.jpg

http://imm.io/1OID

在本地计算机上我创建了一个具有 256 RAM 的虚拟机。 一切工作正常,但我必须承认有点慢...... 但我本地机器上有双核 7400。

我尝试使用以下设置限制 VDS 上的内存使用:

$gif = new Imagick($s['src']);

set_time_limit(0);
$gif->setResourceLimit(Imagick::RESOURCETYPE_MEMORY,32);
$gif->setResourceLimit(Imagick::RESOURCETYPE_MAP,64);

// echo $gif->getResourceLimit(Imagick::RESOURCETYPE_MEMORY);
// echo $gif->getResourceLimit(Imagick::RESOURCETYPE_MAP);
// echo $gif->getResourceLimit(Imagick::RESOURCETYPE_FILE);
// echo $gif->getResourceLimit(Imagick::RESOURCETYPE_DISK);
// echo $gif->getResourceLimit(Imagick::RESOURCETYPE_AREA);
// exit;

$gif = $gif->coalesceImages();

foreach($gif as $frame){
    $frame->cropImage($s['params']['w'], $s['params']['h'], $s['params']['x'], $s['params']['y']);      
    $frame->setImagePage($s['params']['w'], $s['params']['h'], 0, 0);
}   

$gif->writeImages($s['dest_path'] .'/'. $fullname,true);

但是我可以限制处理器使用吗?

VDS速度慢有什么解决办法吗? :|

谢谢大家!

更新:

   print_r(getimagesize($s['src']));
   exit;

   $gif = new Imagick($s['src']);
   etc...

    Array
(
    [0] => 530
    [1] => 150
    [2] => 1
    [3] => width="530" height="150"
    [bits] => 8
    [channels] => 3
    [mime] => image/gif
)

更新2:

pathinfo($s['src'])

(
    [dirname] => images/tmp
    [basename] => 43138a0723d6ae0799564bd6acb8c7b83c8df483.gif
    [extension] => gif
    [filename] => 43138a0723d6ae0799564bd6acb8c7b83c8df483
)

更新3: 如何调试 imagick 扩展? :(

找到了这个包:

有人尝试过吗?

I'm trying to do crop animated gif on VDS with this configuration:

~800MHz and 256 RAM

And it's not working. It just eats memory and processor and after a ~minute returns no responce.

http://i192.photobucket.com/albums/z228/Somebi/no-responce.jpg

http://imm.io/1OID

On local machine i'v created a virtual machine with 256 RAM.
Everything works fine, but a bit slow i must admit...
But i have Duo Core 7400 on local machine.

I have tried to limit memory usage on VDS with these settings:

$gif = new Imagick($s['src']);

set_time_limit(0);
$gif->setResourceLimit(Imagick::RESOURCETYPE_MEMORY,32);
$gif->setResourceLimit(Imagick::RESOURCETYPE_MAP,64);

// echo $gif->getResourceLimit(Imagick::RESOURCETYPE_MEMORY);
// echo $gif->getResourceLimit(Imagick::RESOURCETYPE_MAP);
// echo $gif->getResourceLimit(Imagick::RESOURCETYPE_FILE);
// echo $gif->getResourceLimit(Imagick::RESOURCETYPE_DISK);
// echo $gif->getResourceLimit(Imagick::RESOURCETYPE_AREA);
// exit;

$gif = $gif->coalesceImages();

foreach($gif as $frame){
    $frame->cropImage($s['params']['w'], $s['params']['h'], $s['params']['x'], $s['params']['y']);      
    $frame->setImagePage($s['params']['w'], $s['params']['h'], 0, 0);
}   

$gif->writeImages($s['dest_path'] .'/'. $fullname,true);

But can i limit processor usage?

And is there any solution for slow VDS? :|

Thanks everyone!

update:

   print_r(getimagesize($s['src']));
   exit;

   $gif = new Imagick($s['src']);
   etc...

    Array
(
    [0] => 530
    [1] => 150
    [2] => 1
    [3] => width="530" height="150"
    [bits] => 8
    [channels] => 3
    [mime] => image/gif
)

update2:

pathinfo($s['src'])

(
    [dirname] => images/tmp
    [basename] => 43138a0723d6ae0799564bd6acb8c7b83c8df483.gif
    [extension] => gif
    [filename] => 43138a0723d6ae0799564bd6acb8c7b83c8df483
)

update3:
How to debug imagick extension? :(

Have found this package:
http://fr2.rpmfind.net/linux/RPM/fedora/updates/testing/13/i386/debug/php-pecl-imagick-debuginfo-3.0.0-5.fc13.i686.html

Have anyone tried it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

水晶透心 2024-10-06 22:33:06

您可以增加 php 的最大执行时间,我相信它默认为 60 秒。

在运行时使用 set_time_limit,或在 ini 配置中使用 max_execution_time

好的,从头开始,我看到你已经这样做了。哎哟!

You could increase php's maximum execution time, i believe it defaults to 60 seconds.

At runtime with set_time_limit, or ini config with max_execution_time.

ok, scratch that, i see your already doing it. Doh!

情绪失控 2024-10-06 22:33:06

我将推测 $s['src'] 包含远程 URL。

这可能意味着您真正的麻烦是获取远程图像。防火墙或其他东西可能会导致脚本超时。

首先尝试使用本地图像。我敢打赌半瓶啤酒肯定效果很好。在这种情况下,请尝试使用 file_get_contents() 来获取远程文件。我想我在某处读到过一些内容,说 IMagick 的构造函数在 URL 方面存在问题。

I'm going to speculate that $s['src'] contains a remote URL.

That could mean that your real trouble is fetching the remote image. The firewall or something else could be causing the script to time out.

Try it with a local image instead first. I would bet half a beer that it works fine then. In that case, experiment with fetching the remote file using file_get_contents() instead. I think I read something somewhere that IMagick's constructor has trouble with URLs.

北渚 2024-10-06 22:33:06

尝试在命令行上运行 php 脚本,看看它是否与执行时间有关。

shell> php <your-script-name>

如果 PATH 环境变量中没有 php 的完整路径,您可能需要替换它。

请记住,ImageMagick 针对质量进行了优化;不是为了速度。有一个名为 GraphicsMagick 的类似库,(他们说)它在资源较少的情况下运行良好。如果您仍然遇到资源问题,您可以考虑尝试一下。

Try running your php script on command line to see whether it has anything to do with execution time.

shell> php <your-script-name>

You may have to replace full path to php if it's not in your PATH environment variable.

Keep in mind that ImageMagick is optimized for quality; not for speed. There's a similar library called GraphicsMagick which (they say) is running well with low resources. You may consider trying it if you still experience resource issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文