4 ms·
Tell HN: Turn small images to html for fun
I just made this small thing for fun. Please enjoy! I place it in the public domain. Python code follows. (Sorry about the newlines not coming through)
from sys import argv
from base64 import b64encode
from os.path import split, splitext
ifn = argv[1]
alt, ext = splitext(ifn)
ext = ext.lstrip('.')
ofn = alt+'.html'
alt = split(alt)[1]
ifd = open(ifn, 'rb')
ofd = open(ofn, 'wb')
ofd.write( '<img src="data:image/{0};base64,{1}" alt="{2}" />'.format(ext, b64encode(ifd.read()), alt))
ifd.close()
ofd.close()
- aufreak3 16y agoGimp lets you export images into HTML tables :) It even asks you whether you're sane and really want to do it!
- ff0066mote 16y agoPhotoshop does that too. This method is different because it uses the data URI scheme to encode the (small) image as base64 data in the <img /> tag. No tables here!