[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Anon's challenge: convert a picture into 1px by 1px html

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 11
Thread images: 1

Anon's challenge: convert a picture into 1px by 1px html elements.

This is the best solution I have at the moment, (improved from another anon):
from PIL import Image, ImageOps

im = Image.open("1447035697098.jpg")
# Ratio
MAX_WIDTH = 1000
if im.size[0] > MAX_WIDTH:
r = im.size[0] / im.size[1]
h = int(MAX_WIDTH * r)
im = ImageOps.fit(im, [MAX_WIDTH, h], Image.ANTIALIAS)

x = im.size[0]
y = im.size[1]
pixels = []
w = 0
h = 0
pix = im.load()

for j in range(y):
for i in range(x):
pixels.append('#%02x%02x%02x' % (pix[i, j]))


width = int(x)
q = open('output.html', 'w')
lines = [pixels[i:i + width] for i in range(0, len(pixels), width)]

script = """
document.addEventListener('DOMContentLoaded', function() {
var h = 0;
draw = document.getElementById("draw");
for (var l = 0; l < pix.length; l++) {
h++;
for (var p = 0; p < pix[l].length; p++) {
var newPix = document.createElement('div');
newPix.style.position = "absolute";
newPix.style.height = 1 + "px";
newPix.style.width = 1 + "px";
newPix.style.left = p + "px";
newPix.style.top = h + "px";
newPix.style.backgroundColor = pix[l][p];

draw.appendChild(newPix)
}
}
});

"""
body = """
<html>
<head>
<script>window.pix = %s;</script>
<script>%s</script>"
</head>
<body>
<div id='draw'></div>
</body>
</html>
""" % (str(lines), script)

q.write(body)

q.close()



A 4.7MB image goes to 11.4MB of HTML. Thoughts?
>>
>>57483143
Why?
>>
>>57483164
Why not?
>>
How big gzipped HTML is?
>>
>>57483169
The challenge is raw output / rendering speed. Not compression and delivery
>>
>>57483180
I know, just curious.
>>
>>57483164
>>57483167
>>57483180
>>57483188
Do not post your solution for this. OP is either a pajeet in too deep at his company, or he's trying to make some shit eating DRM for his website.

Go away OP.
>>
A little neater, now that I am done fucking around

from PIL import Image, ImageOps

im = Image.open("1447035902821.jpg")

x, y = im.size[0], im.size[1]
pixels, w, h = [], 0, 0
pix = im.load()

for j in range(y):
temp = []
for i in range(x):
temp.append('#%02x%02x%02x' % (pix[i, j]))
pixels.append(temp)

q = open('output.html', 'w')

body = """
<html>
<head>
<script>window.pix = %s;</script>
<script>
document.addEventListener('DOMContentLoaded', function() {
var h = 0;
draw = document.getElementById("draw");
for (var l = 0; l < pix.length; l++) {
h++;
for (var p = 0; p < pix[l].length; p++) {
var newPix = document.createElement('div');
newPix.style.position = "absolute";
newPix.style.height = 1 + "px";
newPix.style.width = 1 + "px";
newPix.style.left = p + "px";
newPix.style.top = h + "px";
newPix.style.backgroundColor = pix[l][p];

draw.appendChild(newPix)
}
}
});
</script>
</head>
<body>
<div id='draw'></div>
</body>
</html>
""" % (str(pixels))
q.write(body)
q.close()




>>57483223
t. no fun allowed
>>
>>57483223
Doubt it. Why not just use base64 or canvas or something. I can't think of any possible real world use for this
>>
<img height=1 width=1 src=hello.jpg></img>
Yall niggas makin this too hard LOL
>>
>not using a context manager for open files
kill yourself
Thread posts: 11
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.