TImageBase64

Source: source/classes/imageb64.prg

Standalone utility class

TImageBase64 is a utility class that encodes images to Base64 for use in web pages (HTML <img> tags with data URIs). It can also extract and save images from Base64-encoded HTML. The class auto-detects whether the input source is a file path, URL, or plain text.

Key DATA Members

DATATypeDescription
aImageArrayInternal image array from FW_ReadImage
cFileCharacterSource file path or URL (if applicable)
cBase64CharacterBase64 encoded image string
lTagLogicalInclude <img> tags in output
lHtmlLogicalGenerate full HTML document in output
lUrlEncodeLogicalURL-encode the data URI instead of plain base64
nImgWidthNumericImage width in pixels (ACCESS readonly)
nImgHeightNumericImage height in pixels (ACCESS readonly)

Methods

MethodDescription
New( cSource )Create object; optionally load source immediately
SetSource( cSource )Set source: auto-detects file, URL, or base64 text
ChooseFile()Open file picker dialog to select an image
Paste()Load image from clipboard
MakeText( lUrlEncode, lTag, lHtml, cTitle )Generate output text (data URI or HTML)
SaveText( cFile, lUrlEncode, lTag, lHtml )Save output text to file; returns filename or nil
CopyText( lUrlEncode, lTag, lHtml )Copy output text to clipboard; returns the text
SaveImage()Save the decoded image to a file (.jpg or .png)
TestHTML()Generate a test HTML file and open it in the browser

Example: Image to Base64 HTML Tag

#include "FiveWin.ch"

function Main()

   local oImg := TImageBase64():New( "c:\images\photo.jpg" )

   // Generate an HTML img tag with inline base64 data
   oImg:lTag := .T.
   oImg:CopyText()   // copies to clipboard

   // Or save as a complete HTML file
   oImg:lHtml := .T.
   oImg:SaveText( "preview.html" )

   // Open in browser to test
   oImg:TestHTML()

return nil

Notes

See Also