如何创建网站的缩略图?

发布于 2024-08-02 21:41:08 字数 68 浏览 4 评论 0原文

我会猜测已经有一个基于 webkit/gecko 的命令行应用程序(甚至可能作为服务器加速多个页面的渲染)已经在这样做了?

Is would guess that there is already a webkit/gecko based command line app (maybe even working as a server speed up to rending of multiple pages) which is already doing this?

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

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

发布评论

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

评论(1

天涯沦落人 2024-08-09 21:41:08

这是一个示例 Qt4 命令行应用程序,它创建整个网页的屏幕截图 - 易于适应缩略图生成......

#include <QtGui/QApplication>
#include <QtCore/QCoreApplication>
#include <QtGui>
#include <QtWebKit>
#include <QWebPage>
#include <QTextStream>
#include <QSize>

QWebView *view;
QString outfile;

void QWebView::loadFinished(bool ok)
{
        QTextStream out(stdout);
        if (!ok) {
                out << "Page loading failed\n";
                return;
        }
        view->page()->setViewportSize(view->page()->currentFrame()->contentsSize());
        QImage *img = new QImage(view->page()->viewportSize(), QImage::Format_ARGB32);
        QPainter *paint = new QPainter(img);
        view->page()->currentFrame()->render(paint);
        paint->end();
        if(!img->save(outfile, "png"))
                out << "Save failure\n";
        QApplication::quit();
        return;
}

int main(int argc, char *argv[])
{
        QTextStream out(stdout);
        if(argc < 3) {
                out << "USAGE: " << argv[0] << " <url> <outfile>\n";
                return -1;
        }
        outfile = argv[2];
        QApplication app(argc, argv);
        view = new QWebView();
        view->load(QUrl(argv[1]));

        return app.exec();
}

您可以使用 xvfb 也是如此。请参阅此博文了解原文和链接到 python 替代方案。

Here's a sample Qt4 command line app which creates a screengrab of an entire web page - easy to adapt for thumbnail generation....

#include <QtGui/QApplication>
#include <QtCore/QCoreApplication>
#include <QtGui>
#include <QtWebKit>
#include <QWebPage>
#include <QTextStream>
#include <QSize>

QWebView *view;
QString outfile;

void QWebView::loadFinished(bool ok)
{
        QTextStream out(stdout);
        if (!ok) {
                out << "Page loading failed\n";
                return;
        }
        view->page()->setViewportSize(view->page()->currentFrame()->contentsSize());
        QImage *img = new QImage(view->page()->viewportSize(), QImage::Format_ARGB32);
        QPainter *paint = new QPainter(img);
        view->page()->currentFrame()->render(paint);
        paint->end();
        if(!img->save(outfile, "png"))
                out << "Save failure\n";
        QApplication::quit();
        return;
}

int main(int argc, char *argv[])
{
        QTextStream out(stdout);
        if(argc < 3) {
                out << "USAGE: " << argv[0] << " <url> <outfile>\n";
                return -1;
        }
        outfile = argv[2];
        QApplication app(argc, argv);
        view = new QWebView();
        view->load(QUrl(argv[1]));

        return app.exec();
}

You can run this on a server using xvfb too. See this blog post for original and a link to a python alternative.

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