#include <GDIPlus.au3>
#include <ScreenCapture.au3>
;~ $sImage_Path = @SystemDir & "\oobe\images\wpaback.jpg" ;FileOpenDialog("Open image...", "", "All Images (*.png;*.bmp;*.gif;*.jpeg)")
;~ If @error Then Exit
$sImage_Path = @ScriptDir & '\AutoItImage.jpg'
$sDestFile = StringRegExpReplace($sImage_Path, "(.*)(\.[^\.]*$)", "\1_With_Watermark\2")
_ScreenCapture_Capture($sImage_Path, 0, 0, 600, 400, 0)
_ImageSetWaterMark($sImage_Path, $sDestFile, 'Watermark with AutoIt', 0xFF0000, 16, -1, -1, 4)
; Show image
ShellExecute($sDestFile)
;~ Run('MSPaint.exe "' & $sDestFile & '"')
Func _ImageSetWaterMark($sSrcImage, $sDstImage, $sWaterMark, $iColor=0xFF0000, $iFontSize=16, $iLeft=0, $iTop=0, $iFormat=4)
; Initialize GDI+ library
_GDIPlus_StartUp()
Local $hImage = _GDIPlus_ImageLoadFromFile($sSrcImage)
Local $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
Local $hFamily = _GDIPlus_FontFamilyCreate("Arial")
Local $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, 1)
Local $tLayout = _GDIPlus_RectFCreate(0, 0)
Local $hFormat = _GDIPlus_StringFormatCreate($iFormat)
Local $hBrush1 = _GDIPlus_BrushCreateSolid(0xA2FFFFFF)
Local $hBrush2 = _GDIPlus_BrushCreateSolid("0xC4" & Hex(Number($iColor), 6))
Local $hPen = _GDIPlus_PenCreate(0xC4000000, 2)
Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sWaterMark, $hFont, $tLayout, $hFormat)
Local $iWidth = DllStructGetData($aInfo[0], "Width")
Local $iHeight = DllStructGetData($aInfo[0], "Height")
If $iLeft = -1 Then $iLeft = _GDIPlus_ImageGetWidth($hImage) - $iWidth
If $iTop = -1 Then $iTop = _GDIPlus_ImageGetHeight($hImage) - $iHeight
If $iLeft = 0 Then $iLeft = 1
If $iTop = 0 Then $iTop = 1
DllStructSetData($aInfo[0], "X", $iLeft)
DllStructSetData($aInfo[0], "Y", $iTop)
_GDIPlus_GraphicsFillRect($hGraphic, $iLeft, $iTop, $iWidth, $iHeight, $hBrush1)
_GDIPlus_GraphicsDrawRect($hGraphic, $iLeft, $iTop, $iWidth, $iHeight, $hPen)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $sWaterMark, $hFont, $aInfo[0], $hFormat, $hBrush2)
; Save image
Local $sTmp_ImageFile = StringRegExpReplace($sSrcImage, "(.*)(\.[^\.]*$)", "\1_tmp\2")
_GDIPlus_ImageSaveToFile($hImage, $sTmp_ImageFile)
; Free resources
_GDIPlus_PenDispose ($hPen )
_GDIPlus_BrushDispose ($hBrush1 )
_GDIPlus_BrushDispose ($hBrush2 )
_GDIPlus_StringFormatDispose($hFormat )
_GDIPlus_FontDispose ($hFont )
_GDIPlus_FontFamilyDispose ($hFamily )
_GDIPlus_GraphicsDispose ($hGraphic)
_GDIPlus_ImageDispose ($hImage )
_GDIPlus_ShutDown()
If $sDstImage <> $sSrcImage And FileExists($sDstImage) Then
FileMove($sTmp_ImageFile, $sDstImage, 1)
ElseIf $sDstImage = -1 Or $sDstImage = $sSrcImage Or Not FileExists($sDstImage) Then
FileMove($sTmp_ImageFile, $sSrcImage, 1)
EndIf
FileDelete($sTmp_ImageFile)
EndFunc