Display images from websites in your own Gui

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Display images from websites in your own Gui

29 Jul 2017, 17:09

Ever wanted to show an image from some website that you don't want to have to set up a download and then add the image to the Gui and then when the program is done delete the images?
Well now it's possible!
All it takes is to know the image's Url and size and you're ready to go!

Here's a working example for showing an image in a Gui with the function and how to use it:

Code: Select all

Gui, -MinimizeBox +Resize +MinSize500x250
Gui, Add, ActiveX, x0 y0 w350 h100 vWB1, Shell.Explorer

; This can be an image from a website, or an image from your computer. Just specify the path based off of the current script directory.
Edit := WebPic(WB1, "https://autohotkey.com/assets/images/ahk-logo-no-text241x78-180.png", "w241 h78 cFFFFFF")
Gui, Add, Edit, x0 y105 w750 h215 -Wrap +HScroll vEdit TabStop WantReturn t8
Gui, Show, w750 h320, Gui Example
GuiControl,, Edit, % Edit
Return

GuiClose:
ExitApp

GuiSize:
GuiControl, MoveDraw, Edit, % "w" A_GuiWidth " h" A_GuiHeight - 105
Return

;||==================================================================================;||
;|| How to use it:                                                                   ;||
;||		WB                                                                           ;||
;||				the unquoted variable of the ActiveX Gui variable                    ;||
;||		Website                                                                      ;||
;||				Pretty self explainitory                                             ;||
;||		Options                                                                      ;||
;||				Set the image's width and height.                                    ;||
;||				Works the same way Gui works:                                        ;||
;||			w50 h50 cEEEEEE                                                          ;||
;||				These are the default settings.                                      ;||
;||				To change them,                                                      ;||
;||				specify the same way how you would change them for a Gui control     ;||
;||==================================================================================;||

WebPic(WB, Website, Options := "") {
	RegExMatch(Options, "i)w\K\d+", W), (W = "") ? W := 50 :
	RegExMatch(Options, "i)h\K\d+", H), (H = "") ? H := 50 :
	RegExMatch(Options, "i)c\K\d+", C), (C = "") ? C := "EEEEEE" :
	WB.Silent := True
	HTML_Page :=
	(RTRIM
	"<!DOCTYPE html>
		<html>
			<head>
				<style>
					body {
						background-color: #" C ";
					}
					img {
						top: 0px;
						left: 0px;
					}
				</style>
			</head>
			<body>
				<img src=""" Website """ alt=""Picture"" style=""width:" W "px;height:" H "px;"" />
			</body>
		</html>"
	)
	While (WB.Busy)
		Sleep 10
	WB.Navigate("about:" HTML_Page)
	Return HTML_Page
}
Hope you enjoy showing people your pictures with ease!
And thanks to the wonderful person: joedf for showing his usefulness in making this possible. I used part of his Display() function to get it working! Linked :arrow: here

Any questions can be asked here and any comments or addons can be said here, thank you! :D

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

JasonDavisFL
Posts: 12
Joined: 12 Jan 2018, 13:05
Contact:

Re: Display images from websites in your own Gui

09 Feb 2018, 10:04

Awesome just what I need for a Bookmark manager app I am building where I am going to have a Tab that shows all images I have attached to the bookmark record and this is a great way to show them images in the GUI
garry
Posts: 3758
Joined: 22 Dec 2013, 12:50

Re: Display images from websites in your own Gui

15 Feb 2018, 13:39

@Delta Pythagorean, thank you
here also an example to show a picture in a GUI , but it downloads

Code: Select all

F0=http://i.imgur.com/pgCT683.jpg
F1=%a_desktop%\China_Canada_Joke.jpg
SplitPath,f1,,,,nne,
ifnotexist,%f1%
   urldownloadtofile,%f0%,%f1%
Gui, Add, Picture,  w1100 h-1 ,%f1%
Gui, Show,x1 y1 ,%nne%
return
Guiclose:
exitapp
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: Display images from websites in your own Gui

15 Feb 2018, 14:52

garry wrote:@Delta Pythagorean, thank you
here also an example to show a picture in a GUI , but it downloads

Code: Select all

F0=http://i.imgur.com/pgCT683.jpg
F1=%a_desktop%\China_Canada_Joke.jpg
SplitPath,f1,,,,nne,
ifnotexist,%f1%
   urldownloadtofile,%f0%,%f1%
Gui, Add, Picture,  w1100 h-1 ,%f1%
Gui, Show,x1 y1 ,%nne%
return
Guiclose:
exitapp
You are correct. But the goal of the topic is to display the image without downloading it at all.
While it is true that you can show a normal image in a GUI, you cannot display gifs (Animated images) in the GUI without it being all hacky and having a bunch of spaghetti code.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

garry
Posts: 3758
Joined: 22 Dec 2013, 12:50

Re: Display images from websites in your own Gui

15 Feb 2018, 15:26

I tried with ActiveX , plays GIF with mozilla .
Dont' know how to change the variables in ActiveX if once GUI is created , example below change with reload between vlc or mozilla
A drag&drop example with ActiveX ( with vlc / mozilla )
https://autohotkey.com/boards/viewtopic.php?f=6&t=44007

;- variables for ActiveX =
xxa=VideoLAN.VLCPlugin.2 ;- video / music / foto
xxb=Mozilla.Browser ;- for txt / GIF / ahk
;xxb=Shell.Explorer ;- only for PDF
User avatar
seven150528
Posts: 3
Joined: 04 Oct 2021, 23:18

Re: Display images from websites in your own Gui

15 May 2022, 11:06

What a beautiful code!!
I just changed the DPIScale and removing margins, That's all I did.
Thank you for doing this.


Code: Select all

WebPic(WB, Website, Options := "") {
	; https://www.autohotkey.com/boards/viewtopic.php?t=35199
	
	
	RegExMatch(Options, "i)w\K\d+", W), (W = "") ? W := 50 :
	RegExMatch(Options, "i)h\K\d+", H), (H = "") ? H := 50 :
	RegExMatch(Options, "i)c\K\d+", C), (C = "") ? C := "EEEEEE" :
	WB.Silent := True
	W :=  A_ScreenDpi/96*W
	H :=  A_ScreenDpi/96*H
	
	
	HTML_Page :=
	(RTRIM
	"<!DOCTYPE html>
		<html>
			<head>
				<style>
					body {
						background-color: #" C ";
						
						margin: 0;
						padding: 0;
					}
					img {
						top: 0px;
						left: 0px;
					}
				</style>
			</head>
			<body>
				<img src=""" Website """ alt=""Picture"" style=""width:" W "px;height:" H "px;"" />
			</body>
		</html>"
	)
	While (WB.Busy)
		Sleep 10
	WB.Navigate("about:" HTML_Page)
	Return HTML_Page
}

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 77 guests