tags:

views:

370

answers:

2

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?

+6  A: 

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.

Paul Dixon
A: 

hi, my friends how can I call xvfb and this script? Is it something like this:

xvfb-run --server-args="-screen 0" ./wkthumb

[?]

mny thanx

ranieri @ Brazil

ranirani

related questions