﻿#include <GDIPlus.au3>

_GDIPlus_Startup()

Global $sRecordFile = @ScriptDir & "\Images\leer\0.png"
Global $hRecordImg = _GDIPlus_ImageLoadFromFile($sRecordFile)

Global $sImgFile = @ScriptDir & "\Images\Neu\1.png"
Global $aText[2] = ["Billy Idol", "Flesh For Fantasy"]
_CreateNewImage($sImgFile, $aText[0] & @CRLF & $aText[1])
ShellExecute($sImgFile)

Global $sImgFile = @ScriptDir & "\Images\Neu\2.png"
Global $aText[2] = ["Bachman Turner Overdrive", "You Ain't Seen Nothing Yet"]
_CreateNewImage($sImgFile, $aText[0] & @CRLF & $aText[1])
ShellExecute($sImgFile)

_GDIPlus_ImageDispose($hRecordImg)
_GDIPlus_Shutdown()
Exit


Func _CreateNewImage($sImgFile, $sText)
	Local $hImage = _GDIPlus_ImageClone($hRecordImg)
	Local $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
	_GDIPlus_GraphicsSetTextRenderingHint($hGraphic, 5)
	_GDIPlus_GraphicsSetInterpolationMode($hGraphic, 7)
	Local $hBrush = _GDIPlus_BrushCreateSolid(0xFF3C4783)
	Local $hFormat = _GDIPlus_StringFormatCreate()
	Local $hFamily = _GDIPlus_FontFamilyCreate("Arial")
	Local $aRectSize[4] = [170, 150, 420, 140] ; X, Y, W, H
	Local $tLayout = _GDIPlus_RectFCreate($aRectSize[0], $aRectSize[1], $aRectSize[2], $aRectSize[3])
	Local $hFont, $aInfo, $iFontSize = 24
	Do
		If $hFont Then _GDIPlus_FontDispose($hFont)
		$hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, 3)
		$aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sText, $hFont, $tLayout, $hFormat)
		$iFontSize -= 1
	Until ($aInfo[2] = 2) And (StringLen($sText) = $aInfo[1])
	ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $iFontSize = ' & $iFontSize + 1 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
	_GDIPlus_GraphicsDrawRect($hGraphic, $aRectSize[0], $aRectSize[1], $aRectSize[2], $aRectSize[3]) ; <- nur zum anzeigen der benutzen Flaeche (kann weg)
	_GDIPlus_StringFormatSetAlign($hFormat, 1) ; Text horizontal zentrieren
	_GDIPlus_StringFormatSetLineAlign($hFormat, 1) ; Text vertikal zentrieren
	_GDIPlus_GraphicsDrawStringEx($hGraphic, $sText, $hFont, $tLayout, $hFormat, $hBrush)
	_GDIPlus_ImageSaveToFile($hImage, $sImgFile)
	_GDIPlus_FontDispose($hFont)
	_GDIPlus_FontFamilyDispose($hFamily)
	_GDIPlus_BrushDispose($hBrush)
	_GDIPlus_GraphicsDispose($hGraphic)
	_GDIPlus_ImageDispose($hImage)
EndFunc
