User:Eleanorg/1.2/Forbidden Pixels/html grid reproducing a section of banned photo
From XPUB & Lens-Based wiki
#!/usr/bin/python
#-*- coding:utf-8 -*-
import os, re
# this version doesn't use a hash, as key-val pairs were being in stored in some crazy order, other than the order of assignment. here i just use a loop.
#--------- determine image dimensions----------------------------------------#
image = "20by10PixelsSection1.png"
sizeQuery = "identify -format '%w %h' " + image # system command gets image dimensions with ImageMagick
size = os.popen(sizeQuery, 'r').read() # captures output of system call
(width, height) = size.split() # splits ImageMagick output into separate column & row no's
columns = int(width)
rows = int(height)
#--------- print html grid----------------------------------------#
print """
<!DOCTYPE html>
<html>
<head>
<title>Forbidden Pixels: Trial #1</title>
<style type="text/css">
body {
background-color: #333;
color: #eee;
}
#header {
width: 200px;
height: 700px;
float:left;
padding-left: 10px;
margin-top: 20px;
padding-top: 10px;
padding-right: 20px;
border-right: 1px solid #eee;
font-family: sans-serif;
}
.inner {
width: 1040px;
padding-top: 0px;
margin-top: 20px;
float:left;
margin-left: 30px;
background-color: #eee;
}
.pixel {
width: 50px;
height: 50px;
float: left;
border: 1px #000 solid;
padding: none;
margin: none;
}
</style>
</head>
<body>
<div id="header">
<h1>Forbidden Pixels</h1>
<p>A 20 x 10 pixel section of a censored photograph</p>
</div>
<div class="inner">"""
def getcolors ():
row = 0
while row < rows:
column = 0
while column < columns: # for each column in the row..
colorQuery = "convert " + image + " -format '%[pixel:p{" + str(column) + "," + str(row) + "}]' info:-"
colorResult = os.popen(colorQuery, 'r').read() # captures output of system call
color = re.sub("\n", "", colorResult) # strips newline character from end of sys call result
position = (str(column) + "." + str(row)) # concatenates column & row number
# print position + " " + color
print """<span class="pixel" id="pixel_""" + position + """" style="background-color: """ + color + """;"></span>"""
column = column + 1
row = row + 1
getcolors()
print """
</div>
</body>
</html>"""