[R] Insertion image dans page html

Aide et conseils concernant AutoIt et ses outils.
Règles du forum
.
Répondre
touslesmatins
Niveau 6
Niveau 6
Messages : 211
Enregistré le : dim. 15 févr. 2009 01:08
Status : Hors ligne

[R] Insertion image dans page html

#1

Message 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
Modifié en dernier par touslesmatins le jeu. 19 mars 2020 14:57, modifié 1 fois.
Avatar du membre
walkson
Modérateur
Modérateur
Messages : 1020
Enregistré le : ven. 12 août 2011 19:49
Localisation : Hurepoix
Status : Hors ligne

Re: [..] Insertion image dans page html  

#2

Message 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
Cordialement,
Walkson
"Horas non numero nisi serenas " Le canon de midi
(Je ne compte que les heures heureuses)
touslesmatins
Niveau 6
Niveau 6
Messages : 211
Enregistré le : dim. 15 févr. 2009 01:08
Status : Hors ligne

Re: [..] Insertion image dans page html

#3

Message par touslesmatins »

Tres tres interessant ! Un grand merci je drvrais trouver la solution avec ton code ;)
Répondre