def convert_to_html(self): """ Creates a new HTML image that is built by averaging blocks of pixels of a given size. """ html = "<table style='table-layout:fixed; border-spacing: 0;width:{w}px; height:{h}px; border: 1px solid green;'>".format(w=self.width, h=self.height) j = 0 while j < self.height: i = 0 html += "<tr>" while i < self.width: block_pixels = [] for jx in xrange(j, j+self.block_size+1): for ix in xrange(i, i+self.block_size+1): if ix < self.width and jx < self.height: block_pixels.append(self._get_pixel(ix, jx)) if len(block_pixels) > 0: avg_pixel = Pixel.avg_pixels(block_pixels) html += HtmlBlockEmbedder.PIXEL_HTML_TEMPLATE.format(w=self.block_size, h=self.block_size, hex_color=avg_pixel.to_hex_string()) i += self.block_size j += self.block_size html += "</tr>" html += "</table>" return html