Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@psrdotcom
Last active January 27, 2021 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psrdotcom/ce1593f170fe931f9840b4a0f3eae89f to your computer and use it in GitHub Desktop.
Save psrdotcom/ce1593f170fe931f9840b4a0f3eae89f to your computer and use it in GitHub Desktop.
HTML Convert an image to Base64 Image tag
@echo off
@setlocal enableextensions enabledelayedexpansion
SET resultFile="imageTag.html"
if [%1]==[] GOTO :Usage
REM Convert image to base64 string and remove header and footer cert
>NUL certutil -encode %1 tmp.b64 && findstr /v /c:- tmp.b64 > image_template_p2.txt && del tmp.b64
@echo off
REM image_template_p1.txt contents are
REM <img src="data:image/png;base64,
type image_template_p1.txt > %resultFile%
type image_template_p2.txt >> %resultFile%
REM image_template_p3.txt contents are
REM " alt="PSR" />
type image_template_p3.txt >> %resultFile%
ENDLOCAL
echo Image has been succesfully converted to Base64 support img tag.
exit /b
:Usage
echo Input a valid image file path as a parameter
echo Usage: Image2Base64.bat imageFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment