[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]

>Turn images into 1px elements in Python. Rate my solution

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: 15
Thread images: 3

>Turn images into 1px elements in Python.

Rate my solution
from PIL import Image

im = Image.open("qt1.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()


>>
>1px
but why?
>>
>>57891829
Why not??
>>
>>57890631
>using an ide for python
>>
>>57890631
bundle with electron and you're a real app developer
>>
File: hmm.jpg (16KB, 283x283px) Image search: [Google]
hmm.jpg
16KB, 283x283px
>>57890631
> using the whole screen for coding

I guess you really like wasted space
>>
Is there a way I can turn op into a 0x element?
>>
>>57894182

>Having 1 monitor
>>
>>57894589
rude :(
>>
>>57894149
>not using an IDE because you want to be a "real" developer.
>>
>>57890631
>old style string formatting
fuckin dropped
>>
>>57894149
>>57894182
Noobs
>>
>>57895822
Paste this into python IDLE.
http://pastebin.com/raw/WWCgAvXb
>>
File: please.jpg (29KB, 340x396px) Image search: [Google]
please.jpg
29KB, 340x396px
>>57890631
>Apple
>>
>>57895910
.format takes more space, and it's fucking stupid
Thread posts: 15
Thread images: 3


[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.