Page 1 sur 1

[R] Insertion image dans page html

Posté : mer. 18 mars 2020 15:49
par touslesmatins
Bonjour à tous,
Pourriez vous m eclairez sur un sujet sur lequel je bloque...
J insere une variable et Je souhaite insérer une image format png qui ce trouve sur c:\, et l insérer sur une page html qui se trouve également en local et je bloque...
Voici ce que j'utilise :

Code : Tout sélectionner

local $oie=_IEcreate("C:\page.mht", 1)
Local $oBody = _IETagNameGetCollection($oie, "body", 0)	
 _IEDocInsertHTML($oBody, "<p><BR><font color=green size=+15 <big>"&$variable&"</font><BR><img src= " & "C:\a\test.png>" &"<BR><img src= " & "C:\a\test.png>")
mais qui ne fonctionne pas....
merci

Re: [..] Insertion image dans page html  

Posté : jeu. 19 mars 2020 02:32
par walkson
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

Re: [..] Insertion image dans page html

Posté : jeu. 19 mars 2020 14:57
par touslesmatins
Tres tres interessant ! Un grand merci je drvrais trouver la solution avec ton code ;)