Skip to content

Instantly share code, notes, and snippets.


psrdotcom/Image2Base64ImgTag.bat Secret

Last active Jan 27, 2021
What would you like to do?
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%
echo Image has been succesfully converted to Base64 support img tag.
exit /b
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