Skip to content

Commit

Permalink
B64
Browse files Browse the repository at this point in the history
  • Loading branch information
bloodbare committed Mar 8, 2016
1 parent d2d0b94 commit 918daec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
12 changes: 2 additions & 10 deletions src/Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ void Render::start() {

QSize size(width, height);

bool result = page()->render( imagePath, size );
QString result = page()->render( imagePath, size );

if (result) {
finish(true);
} else {
const QString failure = QString("Unable to save %1x%2 image to %3").
arg(width).
arg(height).
arg(imagePath);
finish(false, new ErrorMessage(failure));
}
finish(true, result);
}
12 changes: 9 additions & 3 deletions src/WebPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ bool WebPage::clickTest(QWebElement element, int absoluteX, int absoluteY) {
return res.frame() == element.webFrame();
}

bool WebPage::render(const QString &fileName, const QSize &minimumSize) {
QString WebPage::render(const QString &fileName, const QSize &minimumSize) {
QFileInfo fileInfo(fileName);
QDir dir;
dir.mkpath(fileInfo.absolutePath());
Expand Down Expand Up @@ -257,7 +257,14 @@ bool WebPage::render(const QString &fileName, const QSize &minimumSize) {
p.end();
this->setViewportSize(viewportSize);

return buffer.save(fileName);
QByteArray byteArray;
QBuffer buffer2(&byteArray);
buffer.save(&buffer2, "PNG");
QString iconBase64 = QString::fromLatin1(byteArray.toBase64().data());

buffer.save(fileName);

return iconBase64;
}

QString WebPage::chooseFile(QWebFrame *parentFrame, const QString &suggestedFile) {
Expand Down Expand Up @@ -372,4 +379,3 @@ void WebPage::setPromptAction(QString action) {
void WebPage::setPromptText(QString text) {
m_prompt_text = text;
}

3 changes: 1 addition & 2 deletions src/WebPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class WebPage : public QWebPage {
void setPromptText(QString action);
int getLastStatus();
void setCustomNetworkAccessManager();
bool render(const QString &fileName, const QSize &minimumSize);
QString render(const QString &fileName, const QSize &minimumSize);
virtual bool extension (Extension extension, const ExtensionOption *option=0, ExtensionReturn *output=0);
void setSkipImageLoading(bool skip);
QVariantList consoleMessages();
Expand Down Expand Up @@ -94,4 +94,3 @@ class WebPage : public QWebPage {
};

#endif //_WEBPAGE_H

0 comments on commit 918daec

Please sign in to comment.