For commands with little output and short lines you can do that easily with a combination of a2ps, ghostscript and imagemagick:
Here the output of the command
ls is used as an example.
a2ps -=book -B -q --medium=A4dj --borders=no -o out1.ps &&
-dNOPAUSE -dBATCH -dSAFER \
-dTextAlphaBits=4 -q \
convert -trim out2.png result.png
a2ps creates a vector image of the text. ghostscript rasterises it into a PNG graphic (don't use JPEG, it's the wrong graphic format for this, it's only useful for photorealistic images). Finally imagemagick is used to remove the surrounding white space. Read the man pages and tweak the parameters as necessary.
If the programs are not installed, you can compile and install them with
--prefix=/home/me/.local as a user without admin rights.
EDIT: As mentioned in a comment a solution without the dependency of
a2ps and ghostscript is the following one.
convert label:"$(ls)" result.png