Sign in to follow this  
Followers 0
NinjaGeek

Converting website to image file

5 posts in this topic

There have been several posts on this topic, but none that have come to any resolution. I am trying to see if a script can be written to convert a website to an image file, without having to open the site in a browser (I suppose calling the browser engine to render it behind the scenes?). Is anyone aware of any DLL call that can be made to do this?

Again, this is NOT asking for a screen capture, it needs to be able to run while the computer is locked, so can't do it with _ScreenCapture functions.

Thanks in advance!

Share this post


Link to post
Share on other sites



I'm sorry, not that I know the answer, but what do you need it for?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

This quick and dirty requires ImageMagick and thusly also requires GhostScript. (and i suppose word as well)

You would also need to append the images together at the end if the pdf is more than one page.

You can always hope that one of these smart kids picks it up and polishes it.

#include <Word.au3>

$URL = inputbox ("Site?"  , "What site would you like to capture")
$filename = inputbox ("Name?"  , "What would you like to name the file? (NO EXTENSION)")

inetget ($URL , "c:\" & $filename & ".html")

$oWordApp = _WordCreate ("" , 0 , 0 , 0)

$oDoc = _WordDocOpen ($oWordApp , "c:\" & $filename & ".html")

_WordDocSaveAs ($oDoc , "C:\" & $filename & ".pdf" , 17)

_WordDocClose ($oDoc)

_WordQuit ($oWordApp)

dircreate ("C:\" & $filename & "\")

runwait ("c:\ImageMagick-6.6.6-10\Convert.exe C:\" & $filename & ".pdf" & " c:\" & $filename & "\" & $filename & ".jpg")

shellexecute ("c:\" & $filename & "\" & $filename & "-0.jpg")

exit
Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Look here:

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Here is a less elegant version than Ward's one:

;Coded by UEZ 2011 - alpha version
#include <Clipboard.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

If @OSBuild < 6000 Then Exit MsgBox(16, "Error!", "Script is running properly only on Vista+ os!", 10)

Global $oIE, $GUIActiveX, $oDocument,  $oBody, $BodyWidth, $BodyHeight
Global $hGUI, $hWin, $aWin

Global $URL, $btn, $msg, $hWnd, $input
$hWnd = GUICreate("Save Web Page as an image", 320, 120)
$input = GUICtrlCreateInput("http://www.autoitscript.com/forum/", 10, 5, 300, 20)
$btn = GUICtrlCreateButton("Ok", 40, 35, 240, 70)
ControlFocus($hWnd, "", $btn)
GUISetState()
While $msg <> -3
    $msg = GUIGetMsg()
    Select
        Case $msg = $btn
            ExitLoop
        Case $msg = -3
            Exit
    EndSelect
WEnd
$URL = GUICtrlRead($input)
GUIDelete($hWnd)

Global $i = 0
SplashTextOn("Screenshooting Web Site", "Please wait while taking screenshot", 300, 40, -1, -1, 37, "")
AdlibRegister("Wait", 500)

$oIE = ObjCreate("Shell.Explorer.2")

#region render web site to get height
$hGUI = GUICreate("",  1, 1, -1, -1, $WS_POPUP)
$GUIActiveX = GUICtrlCreateObj ($oIE, 0, 0, 1024, 256)
With $oIE
    .TheaterMode = False
    .FullScreen = True
    .Resizable = False
    .Navigate($URL)
    While .ReadyState <> 4
        Sleep(50)
    WEnd
EndWith

$oDocument = $oIE.document
$oBody = $odocument.body
$oBody.scroll = "no"
$oBody.style.borderStyle = "none"
$BodyWidth = $oBody.scrollWidth
$BodyHeight = $oBody.scrollHeight


GUIDelete($hGUI)
#endregion

$hGUI = GUICreate("",  $BodyWidth,  $BodyHeight, -1, 0, BitOR($WS_CLIPCHILDREN, $WS_POPUP), Default, WinGetHandle(AutoItWinGetTitle()))
$GUIActiveX = GUICtrlCreateObj ($oIE, 0, 0, $BodyWidth,  $BodyHeight + 50)

With $oIE
    .TheaterMode = False
    .FullScreen = True
    .Resizable = False
    .Navigate($URL)
    While .ReadyState <> 4
        Sleep(50)
    WEnd
EndWith

$oDocument = $oIE.document
$oBody =$odocument.body
$oHtml = $odocument.documentElement
$oBody.scroll = "no"
$oBody.style.borderStyle = "none"
$oHtml.style.overflow = 'hidden'


$hWin = WinGetHandle("Program Manager")
$aWin = WinGetPos($hWin)
WinMove($hGUI, "", $aWin[0] - $BodyWidth + 1, $aWin[1] - $BodyHeight + 1) ;hide window
GUISetState(@SW_SHOWNA)       ;Show GUI

Global $hDC = _WinAPI_GetWindowDC($hGUI)
Global $hDC_Dummy = _WinAPI_GetWindowDC(0)
Global $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Dummy)
Global $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Dummy, $BodyWidth, $BodyHeight)
_WinAPI_SelectObject($hMemDC, $hBitmap)
_WinAPI_BitBlt($hMemDC, 0, 0,  $BodyWidth, $BodyHeight, $hDC, 0, 0, $SRCCOPY)
_WinAPI_DeleteDC($hMemDC)
_WinAPI_ReleaseDC($hGUI, $hDC)
_WinAPI_ReleaseDC(0, $hDC_Dummy)
_ClipBoard_Open(0)
_ClipBoard_Empty()
_ClipBoard_SetDataEx($hBitmap, $CF_BITMAP)
_ClipBoard_Close()
_WinAPI_DeleteObject ($hBitmap)
_WinAPI_DeleteDC($hMemDC)
_WinAPI_ReleaseDC(0, $hDC)
GUIDelete($hGUI)
AdlibUnRegister("Wait")
SplashOff()
MsgBox(0, "Information", "Web Site Image copied to clipboard!", 10)
Exit

Func Wait()
    Switch Mod($i, 4)
        Case 0
            ControlSetText("Screenshooting Web Site", "", "Static1", "Please wait while taking screenshot")
        Case 1
            ControlSetText("Screenshooting Web Site", "", "Static1", "Please wait while taking screenshot .")
        Case 2
            ControlSetText("Screenshooting Web Site", "", "Static1", "Please wait while taking screenshot ..")
        Case 3
            ControlSetText("Screenshooting Web Site", "", "Static1", "Please wait while taking screenshot ...")
    EndSwitch
    $i += 1
EndFunc

It is a fast hack and an alpha version!

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0