Last active
December 10, 2015 03:18
-
-
Save Dav1dde/4373754 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// dmd -I../awesomium -L-L. -L-lawesomium-1.6.5 short.d | |
import deimos.awesomium.awesomium; | |
import std.string; | |
void main(string[] args) { | |
string URL = "http://google.com"; | |
string OUTFILE = "./result.jpg"; | |
if(args.length >= 2) { | |
URL = args[1]; | |
} | |
if(args.length >= 3) { | |
OUTFILE = args[2]; | |
} | |
// Create the WebCore with the default options | |
awe_webcore_initialize_default(); | |
// Create a new WebView to load our page | |
awe_webview* webView = awe_webcore_create_webview(1024, 768, false); | |
// Create our URL string | |
awe_string* url_str = awe_string_create_from_ascii(URL.toStringz(), URL.length); | |
// Load the URL into our WebView instance | |
awe_webview_load_url(webView, | |
url_str, | |
awe_string_empty(), | |
awe_string_empty(), | |
awe_string_empty()); | |
// Destroy our URL string | |
awe_string_destroy(url_str); | |
// Wait for WebView to finish loading the page | |
while(awe_webview_is_loading_page(webView)) | |
awe_webcore_update(); | |
// Render our WebView to a buffer | |
const(awe_renderbuffer)* buffer = awe_webview_render(webView); | |
// Make sure our buffer is not NULL; WebView::render will | |
// return NULL if the WebView process has crashed. | |
if(buffer !is null) { | |
// Create our filename string | |
awe_string* file_str = awe_string_create_from_ascii(OUTFILE.toStringz(), OUTFILE.length); | |
// Save our RenderBuffer directly to a JPEG image | |
awe_renderbuffer_save_to_jpeg(buffer, file_str, 90); | |
// Destroy our filename string | |
awe_string_destroy(file_str); | |
} | |
// Destroy our WebView instance | |
awe_webview_destroy(webView); | |
// Destroy our WebCore instance | |
awe_webcore_shutdown(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment