Jump to content

Create image on the fly


Recommended Posts

Is it possible to have a function that create image on the fly based on user input?

Let say, user input "AutoIT Rulez888!!" then this function will create a file with .png extension that will display the text (image) "AutoIT Rulez888!!".

We can choose the font, size and the target filename.

And second, could we create the above image with not only text, but with another predefined image?

Example: '>

When user input "AutoIT Rulez888!!", it will create a balloon (marker) like the one from google above with text "AutoIT Rulez888!!" on the balloon.

So instead of "A" on the baloon (marker), now it's "AutoIT Rulez888!!" on the balloon.

Not possible?

UEZ? :P

Link to comment
Share on other sites

michaelslamet,

the first part isn't that hard to implement. The second part is a little more tricky but also not impossible. ;)

Just look in the Beta help file in GDI+ section how to generate text in a bitmap by calculating its size.

For the second part I will try something when I find some spare time...

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thank you UEZ :)

By saying "Just look in the Beta help file", you mean this will not work with 3.8.8.1 ?

Also, from the old post here, I got a application named "fly" that can create an image on the fly: http://martin.gleeson.com/fly/using.html

Seems pretty simple to use, but surely it cant help for questions no 2.

Should we code it with pure AutoIT or use this external application? Please advice :)

Link to comment
Share on other sites

Yes, a lot of additional GDI+ functions were added to the latest beta and those new functions are not available in 3.3.8.1.

Also your second question can be more easily implemented using the "new" GDI+ functions.

Just have a look to the new functions and its examples.

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Here something you can play with (needs current beta version):

 

;coded by UEZ build 2013-11-24
#AutoIt3Wrapper_Version=b
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

_GDIPlus_Startup()
Global $hGUI = GUICreate("GDI+ Example", 340, 400)
GUISetState()
Global Const $hGfx = _GDIPlus_GraphicsCreateFromHWND($hGUI)

Global $hBitmap = _GDIPlus_CreateMarker("AutoIt" & @LF &"rulez")
;~ Global $hBitmap = _GDIPlus_CreateMarker("A")
_GDIPlus_GraphicsDrawImage($hGfx, $hBitmap, 0, 5)

Do
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _GDIPlus_GraphicsDispose($hGfx)
            _GDIPlus_BitmapDispose($hBitmap)
            _GDIPlus_Shutdown()
            GUIDelete()
            Exit
    EndSwitch
Until False

Func _GDIPlus_CreateMarker($sText, $sFont = "Comic Sans MS", $iFSize = 5.5, $iFColor = 0xFF1F0F0F,$iColorBorder = 0xFF1F0F0F, $iColorFill = 0xFFFF766A) ;beta
    Local Const $hFormat = _GDIPlus_StringFormatCreate()
    Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local Const $hFont = _GDIPlus_FontCreate($hFamily, $iFSize)
    _GDIPlus_StringFormatSetAlign($hFormat, 1)
    Local $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
    Local Const $hGfx_tmp = _GDIPlus_GraphicsCreateFromHDC(_WinAPI_GetWindowDC(0))
    Local $aInfo = _GDIPlus_GraphicsMeasureString($hGfx_tmp, $sText, $hFont, $tLayout, $hFormat)
    _GDIPlus_GraphicsDispose($hGfx_tmp)
    Local $iW = $aInfo[0].Width, $iH = $aInfo[0].Height, $iHF = 3
    If $iW < 9 Then $iW = 9
    Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW * 2, $iH * $iHF)
    Local Const $hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hGfxCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
    _GDIPlus_GraphicsSetTextRenderingHint($hGfxCtxt, $GDIP_TEXTRENDERINGHINT_ANTIALIASGRIDFIT)
    Local Const $hBrushBgColor = _GDIPlus_BrushCreateSolid($iColorFill)
    Local Const $hBrushFontColor = _GDIPlus_BrushCreateSolid($iFColor)
    Local Const $hPen = _GDIPlus_PenCreate($iColorBorder, 2)
    Local Const $hPath = _GDIPlus_PathCreate()
    _GDIPlus_PathAddPie($hPath, $iW / 4, 0, $iW * 1.5 - 2, $iH * 2, 150, 240)
    Local $aCoords = _GDIPlus_PathGetPoints($hPath)
    Local $aPoints[4][2] = [[3]]
    $aPoints[1][0] = $aCoords[2][0]
    $aPoints[1][1] = $aCoords[2][1]
    $aPoints[2][0] = $iW
    $aPoints[2][1] = $iH * $iHF - 7
    $aPoints[3][0] = $aCoords[UBound($aCoords) - 1][0]
    $aPoints[3][1] = $aCoords[UBound($aCoords) - 1][1]
    _GDIPlus_PathAddCurve2($hPath, $aPoints, 0.25)

    _GDIPlus_GraphicsDrawPath($hGfxCtxt, $hPath, $hPen)
    _GDIPlus_GraphicsFillPath($hGfxCtxt, $hPath, $hBrushBgColor)
    _GDIPlus_GraphicsFillEllipse($hGfxCtxt, $iW / 4 + 1, 1, 2 * $iW * 0.75 - $iHF - 1, $iH * ($iHF - 1), $hBrushBgColor)

    _GDIPlus_PathReset($hPath)
    $tLayout.X = $iW - 1
    $tLayout.Y = $iH * 0.25
    _GDIPlus_PathAddString($hPath, $sText, $tLayout, $hFamily, 0, $iFSize + 4, $hFormat)
    _GDIPlus_GraphicsFillPath($hGfxCtxt, $hPath, $hBrushFontColor)

    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BrushDispose($hBrushBgColor)
    _GDIPlus_BrushDispose($hBrushFontColor)
    _GDIPlus_PathDispose($hPath)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_GraphicsDispose($hGfxCtxt)
    Return $hBitmap
EndFunc

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...