Graphics - Simple yet powerful text and image renderer

Post your working scripts, libraries and tools.
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Graphics - Simple yet powerful text and image renderer

04 Aug 2019, 14:56

2022-02-24 NOTE: This does not run on latest v2-beta. Runs fine on AutoHotkey v1.
This project has been superseded by ImagePut for image processing, and TextRender for subtitles and text/image rendering.

Image

❧ [Download] ☙

If your script doesn't work you need to:
  • Add #Persistent to the top of your script or a hotkey.
  • Assign a := RenderText() to a variable or include a time parameter RenderText("✿", "time:8s")
Possible Applications:
  • Rendering text and images to screen
  • Converting images to other file formats (jpg, png) and other encodings (base64)
  • Verifying images are equal
Current working functions:
  • EqualImage()
  • PreprocessImage()
  • RenderImage()
  • RenderImageI() - Interactive version.
  • RenderText()
  • RenderTextI() - Interactive version.
Getting started:
  • Make a new script

    Code: Select all

    #include <Graphics>
    #Persistent
    RenderImageI("https://www.autohotkey.com/boards/styles/simplicity/theme/images/logo.png", "time:15seconds x:10vw")
    
  • (WIP) Tutorials to come!
Code is here: https://github.com/iseahound/Graphics/blob/master/lib/Graphics.ahk

I've been working on this on and off for a long time... It seems there's always new improvements and new issues to address. I'd rather push it out in an incomplete state than wait for completeness. Thanks!
As always suggestions, improvements, and importantly your example scripts are welcome. (Rainmeter widget anyone?)
Last edited by iseahound on 26 Feb 2022, 13:06, edited 7 times in total.
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: Graphics - Simple yet powerful text and image renderer

04 Aug 2019, 14:59

Script for the banner + Old documentation

Code: Select all

#include <Graphics>
#Persistent

g := new Graphics.TextRenderer
g := new Graphics.INTERACTIVE(g) ; Not really needed other than for fun! :D


; Draw backing rectangles.
g.Draw(, "c:33FAB4  x:27.5vw  w:15vw h:160")
g.Draw(, "c:FBDDB5  x:42.5vw  w:15vw h:160")
g.Draw(, "c:F77563  x:57.5vw  w:15vw h:160")

; Draw Text
g.Draw("Graphics", "c:Off", "s:120pt f:(Avenir LT Pro 55 Roman) c:C1BCA6")

; Draw Outline Glow. This is a unique method, because the font color is set to "off" which makes the text transparent.
; Additionally, the outline fill method would normally be used instead of the draw text method contributing to a mismatch in the two font fills.
; In other words when the outline parameter is set, the graphics engine uses a different method to draw the text.
; In this case we use the normal method of drawing text and proceed to use the outline engine to draw the text glow. 
; If these two lines were combined the outline engine would both draw the text and draw the text glow.
g.Draw("Graphics", "c:Off", "s:120pt f:(Avenir LT Pro 55 Roman) c:Off outline:(stroke:0px color:#070707 glow:2px tint:#070707)")
g.Render()
g.Save("hi2.png")
Syntax
Tips and Tricks
List Of Methods
Thanks for the inspiration random person on the internet!
Last edited by iseahound on 04 Aug 2019, 15:20, edited 2 times in total.
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: Graphics - Simple yet powerful text and image renderer

04 Aug 2019, 15:01

It's also v1 compatible if anyone is wondering.
Also, Ctrl to scale the image, Shift to stretch the image.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Graphics - Simple yet powerful text and image renderer

05 Aug 2019, 10:13

Impressive stuff, good job :clap:. Thanks for sharing.

Cheers.
User avatar
boiler
Posts: 16774
Joined: 21 Dec 2014, 02:44

Re: Graphics - Simple yet powerful text and image renderer

05 Aug 2019, 13:30

This looks very useful. I might suggest that since it is v1 compatible, you might want to also post this in the main section of Scripts and Functions since people who only use v1 will rarely if ever check out the v2 subforum, and there are potentially a lot more people there who would make use of this.
User avatar
DataLife
Posts: 445
Joined: 29 Sep 2013, 19:52

Re: Graphics - Simple yet powerful text and image renderer

08 Aug 2019, 23:26

I get Call to nonexistent function.
Specifically: GetMonitorInfo(image)
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
gregster
Posts: 8921
Joined: 30 Sep 2013, 06:48

Re: Graphics - Simple yet powerful text and image renderer

09 Aug 2019, 00:07

DataLife wrote:
08 Aug 2019, 23:26
I get Call to nonexistent function.
Specifically: GetMonitorInfo(image)
Did you include Gdip_All: https://github.com/iseahound/Graphics/blob/master/lib/Gdip_All.ahk ?
This function seems to be in there (lines 2884-2890)
User avatar
DataLife
Posts: 445
Joined: 29 Sep 2013, 19:52

Re: Graphics - Simple yet powerful text and image renderer

09 Aug 2019, 09:23

gregster wrote:
09 Aug 2019, 00:07
DataLife wrote:
08 Aug 2019, 23:26
I get Call to nonexistent function.
Specifically: GetMonitorInfo(image)
Did you include Gdip_All: https://github.com/iseahound/Graphics/blob/master/lib/Gdip_All.ahk ?
This function seems to be in there (lines 2884-2890)
Yes, I already had Gdip_all in my library folder.

I was not aware of an updated version of Gdip_all.

I would recommend any ahk script that requires #include to add a link to that required file in the opening post. This would insure that all files (and correct versions) are available to run the script.

That way I don't have to search for the latest or at least a compatible version of the #include files.
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
logan9
Posts: 33
Joined: 22 Feb 2022, 12:48

Re: Graphics - Simple yet powerful text and image renderer

24 Feb 2022, 16:31

Hello, I'm reading the source of your lib and I could see that only the text supports outline and dropShadow
I'm writing a similar lib: viewtopic.php?f=76&t=100779

I wonder if you could help adapt these parameters to be also supported by the background.
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: Graphics - Simple yet powerful text and image renderer

24 Feb 2022, 17:06

Ah this was broken into

https://github.com/iseahound/TextRender

and

https://github.com/iseahound/ImagePut

a long time ago.

My Gaussian Blur function isn't great, but the outline part should be straightforward. You''ll have to draw a rectangle/circle path, then call GdipDrawPath. Also if you intend to use GDI+ to perform a Gaussian Blur - don't. It's broken and has been replaced by https://docs.microsoft.com/en-us/windows/win32/direct2d/gaussian-blur. I probably say this a lot, but malcev (a user on our forum) is the expert at calling these advanced APIs.
logan9
Posts: 33
Joined: 22 Feb 2022, 12:48

Re: Graphics - Simple yet powerful text and image renderer

24 Feb 2022, 17:19

I see I have tested your gaussian blur function, and the one in the GDI lib, and both didn't return a "good" result.

I have no experience with Direct2D, do you know if it's a GDI(+) bitmap?

Code: Select all

gaussianBlurEffect->SetInput(0, bitmap);
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: Graphics - Simple yet powerful text and image renderer

24 Feb 2022, 17:30

It looks like a WICBitmap. I don't have the conversion functions from GDI+ Bitmap -> WIC Bitmap. I think you can find them here:

viewtopic.php?p=405137
viewtopic.php?t=94345&start=40

and maybe this line from the first link:

Code: Select all

GetPixelFormat(hBitmap) {
   static CLSID_WICImagingFactory := "{CACAF262-9370-4615-A13B-9F5539DA4C0A}"
         , IID_IWICImagingFactory := "{EC5EC8A9-C395-4314-9C77-54D7A935FF70}"
   pFactory := ComObjCreate(CLSID_WICImagingFactory, IID_IWICImagingFactory)
   ; IWICImagingFactory::CreateBitmapFromHBITMAP
   DllCall(NumGet(NumGet(pFactory + 0) + A_PtrSize*21), "Ptr", pFactory, "Ptr", hBitmap, "Ptr", 0, "Int", 0, "PtrP", pIWICBitmap)
   ; IWICBitmap::GetPixelFormat
   VarSetCapacity(GUID, 16, 0)
   DllCall(NumGet(NumGet(pIWICBitmap + 0) + A_PtrSize*4), "Ptr", pIWICBitmap, "Ptr", &GUID)
   ObjRelease(pIWICBitmap), ObjRelease(pFactory)
   Return StringFromGUID(GUID)
}
specifically:

Code: Select all

   ; IWICImagingFactory::CreateBitmapFromHBITMAP
   DllCall(NumGet(NumGet(pFactory + 0) + A_PtrSize*21), "Ptr", pFactory, "Ptr", hBitmap, "Ptr", 0, "Int", 0, "PtrP", pIWICBitmap)
   ; v2 translation
   ComCall(21, pFactory, "Ptr", hBitmap, "Ptr", 0, "Int", 0, "PtrP", pIWICBitmap)
where pIWICBitmap is the return value.

Sources


Ask Teadrinker or malcev for help!
william_ahk
Posts: 482
Joined: 03 Dec 2018, 20:02

Re: Graphics - Simple yet powerful text and image renderer

31 Aug 2023, 23:38

iseahound wrote:
24 Feb 2022, 17:06
Ah this was broken into

https://github.com/iseahound/TextRender

and

https://github.com/iseahound/ImagePut

a long time ago.

My Gaussian Blur function isn't great, but the outline part should be straightforward. You''ll have to draw a rectangle/circle path, then call GdipDrawPath. Also if you intend to use GDI+ to perform a Gaussian Blur - don't. It's broken and has been replaced by https://docs.microsoft.com/en-us/windows/win32/direct2d/gaussian-blur. I probably say this a lot, but malcev (a user on our forum) is the expert at calling these advanced APIs.
Thank you so much for the function! Yours is waay good enough for my use case (image composition).

Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: fischgeek, gongnl, NPerovic, windfancy3 and 16 guests