webkit-image-0.0.svn25399/0000775000175000017500000000000011535367440013275 5ustar neoneowebkit-image-0.0.svn25399/webkit-image-gtk.c0000664000175000017500000000236011501140266016556 0ustar neoneo/* There is no licence for this, I don't care what you do with it */ #include #include #include #include #define WIDTH 2000 /* compile with: * gcc -o webkit-image-gtk webkit-image-gtk.c `pkg-config --cflags --libs webkit-1.0 gio-unix-2.0` * Requires GTK+ 2.20 and WebKitGtk+ 1.1.1 */ static void on_finished (WebKitWebView *view, WebKitWebFrame *frame, GtkOffscreenWindow *window) { GdkPixbuf *pixbuf; GOutputStream *stream; pixbuf = gtk_offscreen_window_get_pixbuf (window); stream = g_unix_output_stream_new (STDOUT_FILENO, TRUE); gdk_pixbuf_save_to_stream (pixbuf, stream, "png", NULL, NULL, NULL); exit (1); } int main (int argc, char **argv) { GtkWidget *window; GtkWidget *view; if (argc != 2) exit (20); gtk_init (&argc, &argv); window = gtk_offscreen_window_new (); view = webkit_web_view_new (); webkit_web_view_load_uri (WEBKIT_WEB_VIEW (view), argv[1]); gtk_widget_set_size_request (view, WIDTH, WIDTH); gtk_container_add (GTK_CONTAINER (window), view); gtk_widget_show_all (window); g_signal_connect (view, "load-finished", G_CALLBACK (on_finished), window); gtk_main (); return 0; } webkit-image-0.0.svn25399/makefile0000664000175000017500000000145011501140266014761 0ustar neoneo#!/usr/bin/make ifneq ($(windir),) MINGWPATH = C:\\PROGRA~1\\mingw\\bin\\ QTPATH = C:\\PROGRA~1\\qt\\ CPP = ${MINGWPATH}c++.exe MOC = ${QTPATH}bin\\moc.exe RM = del CFLAGS = -W -O2 -I${QTPATH}include LDFLAGS = -L${QTPATH}lib LDLIBS = -lQtCore4 -lQtWebKit4 -lQtGui4 -lQtNetwork4 else MOC = moc #MOC = /usr/share/qt4/bin/moc CPP = gcc PACKAGES = QtCore QtGui QtWebKit QtNetwork CFLAGS = -W -O2 `pkg-config --cflags ${PACKAGES}` LDFLAGS = `pkg-config --libs-only-L ${PACKAGES}` LDLIBS = `pkg-config --libs-only-l ${PACKAGES}` endif webkit-image: webkit-image.cpp webkit-image.h $(CPP) -o $@ $(CFLAGS) $(LDFLAGS) webkit-image.cpp $(LDLIBS) webkit-image.h: webkit-image.cpp $(MOC) webkit-image.cpp >$@ clean: ${RM} *.o webkit-image webkit-image.h webkit-image-0.0.svn25399/webkit-image.cpp0000664000175000017500000001025411531226666016350 0ustar neoneo#include #include #include #include #include #include #include #include #include #if QT_VERSION >= 0x040500 #include #include #endif /* using mingw to set binary mode */ #ifdef WIN32 #include #include #define BINARYSTDOUT setmode(fileno(stdout), O_BINARY); #else #define BINARYSTDOUT #endif class Save : public QObject { Q_OBJECT public: Save(QWebPage *p) : page(p) {}; public slots: void loaded(bool ok) { if(ok) { page->setViewportSize(page->mainFrame()->contentsSize()); QImage im(page->viewportSize(), QImage::Format_ARGB32); QPainter painter(&im); page->mainFrame()->render(&painter); QFile f; BINARYSTDOUT if(f.open(stdout, QIODevice::WriteOnly|QIODevice::Unbuffered)) { if(!im.save(&f, "JPEG")) { im.save(&f, "PNG"); } } } emit finish(); } signals: void finish(void); private: QWebPage * page; }; #include "webkit-image.h" int main(int argc, char **argv) { if(argc != 2) return 20; QString url = QString(argv[1]); QApplication a(argc, argv); QWebPage * page = new QWebPage(); Save * s = new Save(page); QStringList environment = QProcess::systemEnvironment(); int idx = environment.indexOf(QRegExp("http_proxy=.*")); if(idx != -1) { QString scheme = "http"; // default QString proxyHost; int proxyPort = 8080; QStringList tmpList = environment.at(idx).split("="); #if QT_VERSION >= 0x040600 // Qt4.6: Use QUrl::fromUserInput // set URL (and guess if proto scheme missing) QUrl url (QUrl::fromUserInput(tmpList.at(1))); #else // set URL QUrl url (tmpList.at(1)); #endif if (url.isValid() && !url.host().isEmpty()) { proxyHost = url.host(); if (url.port() != -1) proxyPort = url.port(); if (!url.scheme().isEmpty()) scheme = url.scheme(); if (scheme == "http") // we support only http { QNetworkProxy proxy; proxy.setType(QNetworkProxy::HttpCachingProxy); proxy.setHostName(proxyHost); proxy.setPort(proxyPort); if (!url.userName().isEmpty()) proxy.setUser(url.userName()); if (!url.password().isEmpty()) proxy.setPassword(url.password()); page->networkAccessManager()->setProxy(proxy); } } else /* manual mode */ { QStringList proto_host_port = tmpList.at(1).split("://"); QStringList host_port; if (proto_host_port.size() == 2) // string has proto { scheme = proto_host_port.at(0); host_port = proto_host_port.at(1).split(":"); } else // no proto (or invalid format with several delimiters) { host_port = tmpList.at(1).split(":"); } if (scheme == "http") // we support only http { proxyHost = host_port.at(0); if(host_port.size() == 2) { bool ok; int port = host_port.at(1).toInt(&ok); if(ok) proxyPort = port; } QNetworkProxy proxy; proxy.setType(QNetworkProxy::HttpCachingProxy); proxy.setHostName(proxyHost); proxy.setPort(proxyPort); page->networkAccessManager()->setProxy(proxy); } } } #if QT_VERSION >= 0x040500 QNetworkDiskCache *diskCache = new QNetworkDiskCache(page); QString location = QDesktopServices::storageLocation(QDesktopServices::CacheLocation); diskCache->setCacheDirectory(location); page->networkAccessManager()->setCache(diskCache); #endif QObject::connect(page, SIGNAL(loadFinished(bool)), s, SLOT(loaded(bool))); QObject::connect(s, SIGNAL(finish(void)), &a, SLOT(quit())); /* set some useful defaults for a webpage */ // page->setViewportSize(QSize(1280,1024)); // don't set size, or it breaks josm */ page->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); page->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); page->mainFrame()->load (QUrl(url)); return a.exec(); } webkit-image-0.0.svn25399/gnome-web-photo-fixed0000775000175000017500000000014311501140266017311 0ustar neoneo#! /bin/bash gnome-web-photo --mode=photo --format=ppm "$1" /dev/stdout |pnmcrop -white |pnmtopng