It's possible to use the standalone class to have pdflatex call the convert tool of the program imagemagick so as to compile and convert to .png an equation at one fell swoop (see this answer for a summary).
A short script to insert the standard input into a minimum document with the correct preamble is all that is required to make your command line widget. This should be possible with most languages; I used python (3) as I'm familiar with the syntax. In a file called textopng.py:
#!/usr/bin/env python
import sys, os, subprocess
# Tested with Python 3.7.2 (4.20.10-arch1-1-ARCH)
# Requires imagemagick
# Name of .tex created (.png will have same name up to the extension)
tex_file = 'outf.tex'
# Preamble code - add additional \usepackage{} calls to this string
# Note: The size option of convert may be useful e.g. size=640
preamble = r'\documentclass[convert={density=900,outext=.png},preview,border=1pt]{standalone}\usepackage{amsmath}'
# Place input in inline math environment
equation = r'\(' + sys.argv[1] + r'\)'
# Construct our mini latex document
latex_string = preamble + '\n' + r'\begin{document}' + equation + r'\end{document}'
# Write to tex_file
with open(tex_file, 'w') as f:
f.write(latex_string)
try:
# Compile .tex with pdflatex. -shell-escape parameter required for convert option of standalone class to work
proc = subprocess.run(["pdflatex", "-shell-escape", tex_file], capture_output=True, text=True,stdin=subprocess.DEVNULL, timeout=3)
if proc.stderr != '':
# Print any error
print('Process error:\n{}'.format(proc.stderr))
if proc.stdout != '':
# Print standard output from pdflatex
print('Process output:\n{}'.format(proc.stdout))
# Timeout for process currently set to 3 seconds
except subprocess.TimeoutExpired:
print('pdflatex process timed out.')
Then, for example,
python3 textopng.py "x=\frac{y^2}{32}"
produced the .png

You may want to edit the preamble code to load additional packages and change the standalone options (see the standalone documentation for the details on these). Let me know if you need help getting the script to work or making it more robust.