Bonjour,
Je vous mets un code que j'ai retrouvé qui comprend plusieurs méthodes
Il compresse et enregistre l'image du PC dans le HTML
Il compresse et enregistre l'image téléchargée dans le HTML
Il affiche l'image internet par lien
Il affiche l'image du PC par lien (ne pas oublier de mettre à jour le chemin)
La page HTML enregistrée (ImageHTML.html) affiche les 3 premiers cas mais pas le dernier si vous utilisez cette page sur un autre PC
C'est la méthode que j'utilise pour envoyer un mail avec image
Code : Tout sélectionner
#include <IE.au3>
$file = FileOpenDialog("Fichier à convertir", @DesktopDir, "All images (*.png;*.jpg)")
If @error Then Exit
FileDelete(@ScriptDir & "\ImageHTML.html")
$oIE = _IECreate()
$f = FileOpen($file, 16)
$t = FileRead($f)
FileClose($f)
$t = _Base64Encode($t)
$w = _Base64Encode(InetRead("https://www.autoitscript.fr/forum/download/file.php?avatar=4001_1422642041.gif",1))
Global $as_Body = '<HTML>' & @CRLF
$as_Body &= '<body>' & @CRLF
$as_Body &= '<img style="width: 200px; height: 200px;" alt="Embedded Image" src="data:image/png;base64,' & $t & '">' & @CRLF ;image du disque dur
$as_Body &= '<br><font color="red" size=18 >' & @CRLF
$as_Body &= 'Hello World' & @CRLF
$as_Body &= '</font>' & @CRLF
$as_Body &= '<br><br><img style="width: 50px; height: 100px;" alt="Embedded Image" src="data:image/gif;base64,' & $w & '">' & @CRLF ; image téléchargé
$as_Body &= '<br><br><img class="fit-picture" src="https://interactive-examples.mdn.mozilla.net/media/examples/grapefruit-slice-332-332.jpg" alt="Grapefruit ">' & @CRLF ; image par lien internet
$as_Body &= '<br><br><img class="fit-picture" src="file:///C:/Users/PC/Pictures/XXX1.png" alt="Grapefruit ">' & @CRLF ; image par lien disque dur METTRE à jour le chemin !
$as_Body &= '</body></HTML>'
_IEDocWriteHTML($oIE, $as_Body)
FileWrite(@ScriptDir & "\ImageHTML.html",$as_Body)
Func _Base64Encode($input)
$input = Binary($input)
Local $struct = DllStructCreate("byte[" & BinaryLen($input) & "]")
DllStructSetData($struct, 1, $input)
Local $strc = DllStructCreate("int")
Local $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _
"ptr", DllStructGetPtr($struct), _
"int", DllStructGetSize($struct), _
"int", 1, _
"ptr", 0, _
"ptr", DllStructGetPtr($strc))
If @error Or Not $a_Call[0] Then
Return SetError(1, 0, "") ; error calculating the length of the buffer needed
EndIf
Local $a = DllStructCreate("char[" & DllStructGetData($strc, 1) & "]")
$a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _
"ptr", DllStructGetPtr($struct), _
"int", DllStructGetSize($struct), _
"int", 1, _
"ptr", DllStructGetPtr($a), _
"ptr", DllStructGetPtr($strc))
If @error Or Not $a_Call[0] Then
Return SetError(2, 0, ""); error encoding
EndIf
Return DllStructGetData($a, 1)
EndFunc ;==>_Base64Encode