Page 1 sur 1
[..]Insérer du text en surimpression dans une image
Posté : ven. 05 févr. 2010 11:30
par pierrotm777
Bonjour,
Je cherche s'il est possible de tagger une image bmp ou jpg avec du texte (type de la police et sa taille réglable) .
Du texte en surimpression somme toute !
Existe il une solution simple pour convertir une image bmp en jpg avec choix (ou pas) de la compression !
Ce lien pourrait-il être utilisable ?
http://www.autoitscript.com/forum/index ... ntry713237
Merci de votre aide !

Re: [..]Insérer du text en surimpression dans une image
Posté : ven. 05 févr. 2010 13:33
par timmalos
Cherchez dans le dossier Exemples de votre installation Autoit, dans Gui et Advanced vous avez un fichier Emboss qui fait ce que vous voulez;
Re: [..]Insérer du text en surimpression dans une image
Posté : sam. 06 févr. 2010 11:42
par pierrotm777
Merci timmalos,
J'essaie de créer une fonction à partir de l'exemple emboss.au3, permettant:
-de charger une image
-de définir un texte
-de définir la font du texte
-de définir la taille du texte
-de définir la position X du texte
-de définir la position Y du texte
Voici ma tentative:
► Afficher le texte
Code : Tout sélectionner
Func TextToImage($PictureBMP,$sString,$FontName,$FontSize,$XsString,$YsString)
;$PictureBMP.....: Picture's name to load
;$sString........: Text to write on the picture
;$FontName.......: Font name
;$FontSize.......: Font's size
;$XsString.......: X text's position
;$YsString.......: Y text's position
; ===============================================================================================================================
; Global variables
; ===============================================================================================================================
Global $DateTime = _Date_Time_GetSystemTime()
Global $DateTimeCorrected = StringReplace(StringReplace(StringReplace(_Date_Time_SystemTimeToDateTimeStr($DateTime),"/",""),":","")," ","_")
Global $hBitmap, $hImage, $hGraphic, $hFamily, $hFont, $tLayout, $hFormat, $aInfo, $hBrush1, $hBrush2, $iWidth, $iHeight, $hPen
;Global $sString = " Created with AutoIt "
Global $sString = $DateTimeCorrected
; Initialize GDI+ library
_GDIPlus_StartUp()
; Capture screen
;$hBitmap = _ScreenCapture_Capture(@Scriptdir & '\'& $PictureBMP)
$hBitmap = @Scriptdir & '\'& $PictureBMP
; Load image and emboss text
$hImage = _GDIPlus_ImageLoadFromFile(@Scriptdir & '\'& $PictureBMP)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 16, 1)
$tLayout = _GDIPlus_RectFCreate(0, 0)
$hFormat = _GDIPlus_StringFormatCreate(2)
$hBrush1 = _GDIPlus_BrushCreateSolid(0xA2FFFFFF)
$hBrush2 = _GDIPlus_BrushCreateSolid(0xC4FF0000)
$hPen = _GDIPlus_PenCreate(0xC4000000, 2)
$aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat)
$iWidth = DllStructGetData($aInfo[0], "Width" )
$iHeight = DllStructGetData($aInfo[0], "Height")
_GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $iWidth, $iHeight, $hBrush1)
_GDIPlus_GraphicsDrawRect($hGraphic, 1, 1, $iWidth, $iHeight, $hPen )
_GDIPlus_GraphicsDrawStringEx($hGraphic, $sString, $hFont, $aInfo[0], $hFormat, $hBrush2)
; Save image
_GDIPlus_ImageSaveToFile($hImage, @Scriptdir & '\'& $PictureBMP)
; 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()
; Show image
;Run("MSPaint.exe " & '"' & @Scriptdir & '\'& $PictureBMP')
EndFunc
Mais je pense qu'il y a des erreurs !
Si vous pouviez me corriger svp?
Merci d'avance !!