为 cutycapt 和 imagemagic 生成缩略图生成更多吞吐量
我正在寻找一种解决方案来生成网站列表屏幕截图的缩略图,并保存到磁盘。
我发现以下命令可以做到这一点。我在 ubuntu 中得到了一个有效的 shell 脚本,它可以很好地生成图像。 (CutyCapt + ImageMagick 软件包)
cutycapt --url=http://www.yahoo.com --out=yahoo.png
convert yahoo.png -thumbnail 150x180^ -gravity NorthWest -extent 150x180 yahoothumb.jpg
但是,它是连续的并且需要大量时间。我想创建一个 PHP 或 Python 脚本,并将其作为 Apache 中的网页托管。然后一个单独的程序将生成多个请求以增加生成图像的吞吐量。
我首先尝试了PHP。
<?php echo exec('cutycapt --url=http://www.google.com --out=/var/www/google.png --javascript=on');?>
CutyCapt 失败并显示以下内容: CutyCapt:无法连接到X 服务器。 我使用与运行常规 shell 脚本相同的身份/用户来运行 PHP/Apache。
顺便说一句,我是一名 C# 开发人员。所以对PHP、Linux、Scripts相对不太熟悉。我可以处理 PHP、Apache 的配置文件:)
我尝试过使用 .NET 在内存中启动 IE,但它很麻烦,而且也不会产生最佳结果 + 需要 STA:所以吞吐量会非常低。
I am looking for a solution to generate thumbnail images of screen shots of list of webs sites, and save to disk.
I found the following commands can do that. And I got a working shell script in ubuntu, which generates the images fine. (CutyCapt + ImageMagick packages)
cutycapt --url=http://www.yahoo.com --out=yahoo.png
convert yahoo.png -thumbnail 150x180^ -gravity NorthWest -extent 150x180 yahoothumb.jpg
But, it is sequential and taking lot of time. I thought of creating a PHP or Python script, which I will host as a web page in Apache. Then a separate program will generate multiple requests to increase the throughput of generating images.
I tried PHP first.
<?php echo exec('cutycapt --url=http://www.google.com --out=/var/www/google.png --javascript=on');?>
And CutyCapt fails with following:
CutyCapt: Can not connect to X Server.
I am running PHP/Apache with the same Identity/user that I run my regular shell script with.
Btw, I am a C# developer. So relatively less familiar with PHP, Linux, Scripts. I can deal with config files for PHP, Apache though :)
I have tried using .NET to launch IE in memory but it's cumbersome and also doesn't produce best results + needs STA: so it will be very less throughput.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经使用了 Xvfb 和 CutyCapt 组合,详细信息请参见 此页面已经生产了几年,没有出现任何问题。事实上,我发现这个组合非常可靠,我编写了一个 Ruby 包装器库 (capit) 来简化使用我正在开发的一些新的 Ruby 应用程序中的组合。
另外,虽然我没有在生产中使用它,但我已经能够使用 PhantomJS 的渲染功能复制类似的结果 库也是如此。
编辑:
您可能需要查看这篇文章作为示例如何将 CutyCapt 作为某种服务运行。
I have used the Xvfb and CutyCapt combination detailed on this page in production for a few years without a problem. In fact, I found the combination so reliable, I wrote a Ruby wrapper library (capit) to simplify using the combination from within some new Ruby applications I'm working on.
Also, though I haven't used it in production, I've been able to replicate similar results with the rendering functionality of the PhantomJS library as well.
EDIT:
You may want to check out this article for an example of how to run CutyCapt as a service of sorts.
不要依赖外部程序来进行图像操作,而是尝试使用 PHP 的内置 GD图片库。根据我的经验,它速度超快且非常广泛,提供所有图像分析和操作功能。
这里是我几年前用 PHP 编写的缩略图脚本,除了提供很多选项之外,还集成了一些自动加载并为其创建的图像添加边框的技巧。抱歉,该代码是单一用途的,但它采用的技术是可重复的。 这是正在运行的脚本。
编辑:
我不知道
cutycapt
做了什么。现在看来 这个问题 与您正在尝试的内容相关去做;将网页转换为 PDF 作为中间格式可能会让您离目标至少更近一步。Instead of relying on an external program to do your image manipulations, try using PHP's built-in GD image library. In my experience, it's super fast and very extensive, providing any and all image analysis and manipulation functionality.
Here's a thumbnailer script I wrote in PHP years ago that, in addition to providing a lot of options, integrates some trickery to automatically load and add borders to the images it creates. Sorry the code is kind of single-purpose, but the techniques it employs are repeatable. Here is the script in action.
Edit:
I was unaware what
cutycapt
did. Now it seems like this question is related to what you're trying to do; converting a web page to a PDF as a go-between format may get you at least one step closer to the goal.