-
Notifications
You must be signed in to change notification settings - Fork 2
/
vector-pixels.html
415 lines (284 loc) · 19.9 KB
/
vector-pixels.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=510">
<link rel="stylesheet" href="/and/style/in/reset.css" type="text/css" />
<link rel="stylesheet" href="/and/style/in/grid.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="/and/style/in/bnf.css" />
<link rel="start" href="/and/" title="Home" />
<link rel="alternate" type="application/atom+xml" title="Recent Entries" href="/and/feed/us/recent_entries.xml" />
<script type="text/javascript" src="/and/scripts/being/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="/and/scripts/being/scripts.js"></script>
<title>I like tight pants and vector pixels</title>
<meta property="og:title dc:title" content="I like tight pants and vector pixels"/>
<meta property="og:type" content="article"/>
<meta property="og:url" content="http://i.liketightpants.net/and/vector-pixels"/>
<meta property="og:image" content="http://i.liketightpants.net/and/assets/called/vector_pixel_city.png"/>
<meta property="og:site_name" content="I like tight pants and mathematics"/>
<meta property="og:description dc:description"
content="Creating a vector image from a raster image usually consists of imagining some kind of curve, responsible for the pixels. But this is guess work at best. Why don’t we work with what’s actually there—points?"/>
<meta name="description"
content="Creating a vector image from a raster image usually consists of imagining some kind of curve, responsible for the pixels. But this is guess work at best. Why don’t we work with what’s actually there—points?"/>
<meta property="fb:admins" content="1488294875"/>
<meta property="mt:entry_basename" content="vector-pixels" />
<meta property="dc:modified" content="2013-02-21T16:43:26" />
</head>
<body>
<div id="header" class="container_7">
<div class="grid_2">
<h1><a href="/and/">i . like tight pants . net</a></h1>
</div>
<div class="grid_3">
<ul>
<li ><a href="/and/hybrid-publishing-back-to-the-future-publishing-theses-at-the-kabk">latest</a></li>
<li><a href="/and/about">about</a></li>
<li ><a href="/and/archives">index</a></li>
</ul>
</div>
<div class="grid_2">
<p class="byline" id="recent_entries">New entries published Monday and Thursday, 22:00 CET (<a href="/and/feed/us/recent_entries.xml">RSS</a>)</p>
</div>
</div>
<div id="content" class="container_7">
<div class="sidebar grid_1">
<img src="/and/assets/that/are/pictures/of/author/bnf.png" style="width:100px;height:100px;" alt="" />
<h4 class="author" property="dc:created" content="2011-11-25T16:14:10">November 25, 2011</h4>
<h4 class="author">by <span property="dc:creator">bnf</span></h4>
<p> </p>
<hr />
<h4>Other articles by bnf</h4>
<dl>
<dt><a href="/and/ufo2otf-makes-otfs-webfonts-and-css-from-ufo">ufo2otf Makes OTF’s, Webfonts and CSS From UFO’s</a></dt>
<dd>November 5, 2013 8:57 PM</dd>
<dt><a href="/and/it-might-be-a-unix-sin-but-i-would-like-you-to-add-dot-t-x-t-as-the-extension-of-your-readme-file">It Might Be a Unix Sin But I Would Like You to Add .txt As the Extension of Your README file</a></dt>
<dd>April 30, 2013 7:51 PM</dd>
<dt><a href="/and/programmatically-manipulating-typefaces">Programmatically manipulating typefaces</a></dt>
<dd>May 2, 2012 11:43 AM</dd>
<dt><a href="/and/downloading-funghi">Downloading funghi, from Wikimedia Commons</a></dt>
<dd>February 3, 2012 5:36 PM</dd>
<dt><a href="/and/absolute-beginners-unix-for-art-students-part-2">Absolute Beginners: Unix for Art Students – Part 2</a></dt>
<dd>December 2, 2011 1:16 AM</dd>
</dl>
<h4>bnf’s comments</h4>
<ul>
<li>Dear Ned, thanks for your reaction, and the link to ... <a href="/and/hackers-culture-and-the-fear-of-wysiwyg#comment-317" title="full comment on: Hacker Culture and the Fear of WYSIWYG">read more</a></li>
<li>As a programmer, what I find more worrying is that ... <a href="/and/hackers-culture-and-the-fear-of-wysiwyg#comment-311" title="full comment on: Hacker Culture and the Fear of WYSIWYG">read more</a></li>
<li>Welcome <a href="/and/hackers-culture-and-the-fear-of-wysiwyg#comment-310" title="full comment on: Hacker Culture and the Fear of WYSIWYG">read more</a></li>
<li>Comparatively, the offer of WYSIWYG libraries is meagre. Luckily, the ... <a href="/and/hackers-culture-and-the-fear-of-wysiwyg#comment-307" title="full comment on: Hacker Culture and the Fear of WYSIWYG">read more</a></li>
<li>Good call. So I should add a part to the ... <a href="/and/ufo2otf-makes-otfs-webfonts-and-css-from-ufo#comment-271" title="full comment on: ufo2otf Makes OTF’s, Webfonts and CSS From UFO’s">read more</a></li>
<li>By the way, a related project (that might make ufo2otf ... <a href="/and/ufo2otf-makes-otfs-webfonts-and-css-from-ufo#comment-269" title="full comment on: ufo2otf Makes OTF’s, Webfonts and CSS From UFO’s">read more</a></li>
<li>Never mind, I have found a solution more easy still. ... <a href="/and/48-hours-of-writing-stylesheets-with-etherpad-and-a-gong#comment-268" title="full comment on: 48 Hours of Writing Stylesheets with Etherpad and a Gong">read more</a></li>
<li>In PHP, it would be something like this:<?php header("Content-type: text/css"); ... <a href="/and/48-hours-of-writing-stylesheets-with-etherpad-and-a-gong#comment-267" title="full comment on: 48 Hours of Writing Stylesheets with Etherpad and a Gong">read more</a></li>
<li>With PHP, there still exists some link between the urls ... <a href="/and/48-hours-of-writing-stylesheets-with-etherpad-and-a-gong#comment-263" title="full comment on: 48 Hours of Writing Stylesheets with Etherpad and a Gong">read more</a></li>
<li>hh <a href="/and/no-one-starts-from-scratch-type-design-and-the-logic-of-the-fork#comment-254" title="full comment on: No-one Starts From Scratch: Type Design and the Logic of the Fork">read more</a></li>
</ul>
<hr />
<h4>Other writers</h4>
<ul>
<li>glit</li>
<li>jenseits</li>
<li>habitus</li>
<li>tellyou</li>
<li>baseline</li>
<li>bnf</li>
</ul>
</div>
<div class="post grid_5">
<p class="byline">
<a href="/and/we-like-tight-pants-and-mathematics">Previous</a>
/ <a href="/and/hybrid-publishing-back-to-the-future-publishing-theses-at-the-kabk">Next</a>
</p>
<div class="article grid_3 alpha omega suffix_2">
<h4 property="mt:entry_title">Vector pixels</h4>
<article property="mt:entry_id" content="33" class="entry" id="entry-33">
<p>
<img src="/and/assets/called/vector_pixel_city_pixels.png" style="width:16px;height:16px;" alt="A stylised image of a skyscraper, in 16 by 16 pixels." title="" />
<object type="image/svg+xml" style="width:384px;height:384px;" data="/and/assets/called/vector_pixel_city.svg">
<img src="/and/assets/called/vector_pixel_city.png" style="width:384px;height:384px;" alt="A stylised image of a skyscraper. The building is made out of square shapes on a 16 by 16 grid. The squares have rounded corners." />
</object>
</p>
<pre style="">#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Turns an image into a two-colored grid of vectorpixels: squares,
circles, or squares with rounded corners.
Creating a vector image from a raster image usually consists of
imagining some kind of curve, responsible for the pixels. But this
is guess work at best. Why don’t we work with what’s actually
there—points?
This script turns an image into a grid of vector squares, circles,
or squares with rounded corners.
usage (command line):
python vectorpixel.py inputimage.png > outputimage.svg
TODO: allow multi-colour pictures, implement vertical and horiontal scanlines """
import Image
import sys
class Vectorpixel:
def __init__(self, image):
self.i = Image.open(image).convert("1")
self.px = self.i.load()
self.constructed = False
def construct(self, grid=24, line=1, rounded=4, test=(lambda x: x == 0)):
self.grid = grid
self.line = line
self.rounded = rounded
self.width = self.height = self.grid - 2 * self.line
self.test = test
self.fill = '#000000'
self.constructed = True
def _yieldlocations(self):
for x in range(self.i.size[0]):
for y in range(self.i.size[1]):
if self.test(self.px[x,y]):
yield (x,y)
def _mkelements(self):
for l in self._yieldlocations():
yield "<rect x='%s' y='%s' width='%s' height='%s' rx='%s' fill='%s'/>" % (
self.grid * l[0] + self.line, self.grid * l[1] + self.line, self.width, self.height, self.rounded, self.fill)
def _format(self):
output = '<svg xmlns="http://www.w3.org/2000/svg" width="%s" height="%s">\n' % (self.i.size[0] * self.grid, self.i.size[1] * self.grid)
for e in self._mkelements():
output += e
output += '\n'
output += '</svg>'
return output
def generate(self):
if not self.constructed:
self.construct()
return self._format()
if __name__ == "__main__":
if len(sys.argv) != 2:
sys.exit("usage (command line):\npython vectorpixel.py inputimage.png > outputimage.svg")
v = Vectorpixel(sys.argv[1])
v.construct()
print v.generate()<br /><br style="" /></pre>
<p>Download <a href="/assets/called/vectorpixels.py">vectorpixels.py</a></p>
</article>
<h4 class="comments-header">1 Comments</h4>
<div id="comments" class="comments">
<div class="comments-content">
<div property="mt:comment_id" content="151" id="comment-151" resource="/and/vector-pixels#comment-151" class="comment">
<div class="comment-editor" property="mt:comment_text">
This script requires the Python Imaging Library. To install the Python Imaging Library, make sure you have <a href="/and/installing-compilers">installed a compiler</a>. Then run:
<pre>sudo easy_install Image</pre>
</div>
<p class="byline" >
<img src="/and/assets/that/are/pictures/of/author/baseline.png" width="18" height="18" />
by <a property="dc:creator" href="http://i.liketightpants.net/authors#baseline">baseline</a> - <a href="/and/vector-pixels#comment-151"><span property="dc:created" content="2012-02-28T17:38:25">February 28, 2012 5:38 PM</span></a><br />
<a title="Reply" href="javascript:void(0);" onclick="mtReplyCommentOnClick(151, 'baseline')">Reply</a>
</p>
</div>
<div class="comments-parent-container" style="margin-left: 20px;">
</div>
<a title="Reply" href="#reply">Reply</a>
</div>
<div class="comments-open" id="comments-open">
<h4 class="comments-open-header">Leave a comment</h4>
<div class="comments-open-content">
<div id="comment-greeting"></div>
<form method="post" action="/comments.cgi">
<input type='hidden' name='csrfmiddlewaretoken' value='sOm1up8Ki2jPbd012lDsDUZsv78nagPd' />
<input id="id_parent" name="parent" type="hidden" />
<input id="id_entry" name="entry" type="hidden" value="33" />
<div id="comments-open-data">
<div id="comment-form-name">
<div class="alpha grid_1"><label for="id_author" class="span-4">Name</label></div>
<div class="omega grid_2"><input id="id_author" maxlength="300" name="author" required="required" size="30" type="text" /></div>
</div>
<div id="comment-form-email">
<div class="alpha grid_1"><label for="id_email" class="span-4">Email address</label></div>
<div class="omega grid_2"><input id="id_email" maxlength="381" name="email" required="required" size="30" type="email" /></div>
</div>
<div id="comment-form-url">
<div class="alpha grid_1"><label for="id_url" class="span-4">URL</label></div>
<div class="omega grid_2"><input id="id_url" maxlength="765" name="url" size="30" type="url" /></div>
</div>
</div>
<div id="comment-form-reply" style="display:none">
<input type="checkbox" id="comment-reply" name="comment_reply" value="" onclick="mtSetCommentParentID()" />
<label for="comment-reply" id="comment-reply-label"></label>
</div>
<div id="comments-open-text">
<label for="id_text">Text:</label><br />
<p class="byline">For formatting your post, you can use html tags like <p> and <br />. Whitespace for now is eaten up, like in HTML. we are sorry—we will have a more friendly commenting option in place shortly!</p>
<textarea cols="40" id="id_text" name="text" required="required" rows="15" style="width:100%">
</textarea>
<!-- <textarea id="comment-text" name="text" rows="15" style="width:100%;" onfocus="mtCommentFormOnFocus()"></textarea> -->
</div>
<p class="byline" id="comments-open-license">By submitting your comment, you agree to license it under the <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution Share-Alike license</a>, the same license used for the text of the blog.</p>
<div id="comments-open-captcha">
<div class="alpha grid_1"><label for="id_captcha_code">Anti-spam: What is the last name of David?</label></div>
<div class="omega grid_2"><input id="id_captcha_code" name="captcha_code" required="required" size="30" type="text" /></div>
</div>
<div id="comments-open-footer">
<!-- <input type="submit" accesskey="v" name="preview_button" id="comment-preview" value="Preview" onclick="this.form.preview.value='1';" /> -->
<input type="submit" accesskey="s" name="post" id="comment-submit" value="Submit" />
</div>
</form>
</form>
</div>
</div>
</div><!-- / comments -->
</div> <!-- / article grid_3 -->
<hr />
</div> <!-- / post grid_5-->
<div class="sidebar grid_1">
<h4>Latest articles</h4>
<dl>
<dt><a href="/and/hybrid-publishing-back-to-the-future-publishing-theses-at-the-kabk">Hybrid Publishing Back To The Future Publishing Theses at the KABK</a></dt>
<dd>May 10, 2018 10:07 AM</dd>
<dt><a href="/and/finding-red-letterboxes-in-belgium">Finding Red Letterboxes In Belgium</a></dt>
<dd>May 10, 2018 10:05 AM</dd>
<dt><a href="/and/the-underwater-screen-or-lessons-from-wordperfect">The Underwater Screen Or Lessons From Wordperfect </a></dt>
<dd>June 10, 2014 6:21 PM</dd>
<dt><a href="/and/hackers-culture-and-the-fear-of-wysiwyg">Hacker Culture and the Fear of WYSIWYG</a></dt>
<dd>May 22, 2014 11:40 PM</dd>
<dt><a href="/and/graphic-design-is-a-nostalgic-field"> Graphic Design Is A Nostalgic Field </a></dt>
<dd>February 19, 2014 7:02 PM</dd>
<dt><a href="/and/who-makes-standards">Who gets to write the web: the power struggles around the standards</a></dt>
<dd>November 20, 2013 9:08 PM</dd>
<dt><a href="/and/ufo2otf-makes-otfs-webfonts-and-css-from-ufo">ufo2otf Makes OTF’s, Webfonts and CSS From UFO’s</a></dt>
<dd>November 5, 2013 8:57 PM</dd>
<dt><a href="/and/no-one-starts-from-scratch-type-design-and-the-logic-of-the-fork">No-one Starts From Scratch: Type Design and the Logic of the Fork</a></dt>
<dd>October 9, 2013 8 PM</dd>
<dt><a href="/and/i-need-my-generic-font-medicine">I Need My Generic Font Medicine</a></dt>
<dd>October 9, 2013 7:55 PM</dd>
<dt><a href="/and/48-hours-of-writing-stylesheets-with-etherpad-and-a-gong">48 Hours of Writing Stylesheets with Etherpad and a Gong</a></dt>
<dd>October 8, 2013 8:06 PM</dd>
</dl>
<h4>Latest Comments</h4>
<ul>
<li><strong>Sujon Ahmad:</strong> Keep it up <a href="/and/release-early-release-often-version-numbers-for-typefaces#comment-338" title="full comment on: Release Early Release Often Version Numbers For Typefaces">read more</a></li>
<li><strong>Carly Durocher:</strong> I really like the stylized penrose triangle would you mind ... <a href="/and/illustration#comment-337" title="full comment on: Illustration">read more</a></li>
<li><strong>michaël:</strong> The recent evolution of MediaWiki is worth mentioning. One of ... <a href="/and/hackers-culture-and-the-fear-of-wysiwyg#comment-336" title="full comment on: Hacker Culture and the Fear of WYSIWYG">read more</a></li>
<li><strong>jaromil:</strong> Check the Linux Action Show on Tomb https://www.dyne.org/software/tomb there can ... <a href="/and/hackers-culture-and-the-fear-of-wysiwyg#comment-335" title="full comment on: Hacker Culture and the Fear of WYSIWYG">read more</a></li>
<li><strong>Ian Hickson:</strong> The member list is the one on the charter (it's ... <a href="/and/who-makes-standards#comment-334" title="full comment on: Who gets to write the web: the power struggles around the standards">read more</a></li>
<li><strong>habitus:</strong> Dear Ian, thank you for taking the time to respond. ... <a href="/and/who-makes-standards#comment-333" title="full comment on: Who gets to write the web: the power struggles around the standards">read more</a></li>
<li><strong>Ian Hickson:</strong> The part about the WHATWG membership is wrong. The WHATWG ... <a href="/and/who-makes-standards#comment-332" title="full comment on: Who gets to write the web: the power struggles around the standards">read more</a></li>
<li><strong>Erik:</strong> Good points. Also: writing UI is hard. <a href="/and/the-underwater-screen-or-lessons-from-wordperfect#comment-327" title="full comment on: The Underwater Screen Or Lessons From Wordperfect ">read more</a></li>
<li><strong>nike shox:</strong> do not want to be t basket vans femme pas ... <a href="/and/no-one-starts-from-scratch-type-design-and-the-logic-of-the-fork#comment-324" title="full comment on: No-one Starts From Scratch: Type Design and the Logic of the Fork">read more</a></li>
<li><strong>Tolan Blundell:</strong> As someone who's written a moderately complex CMS from scratch ... <a href="/and/hackers-culture-and-the-fear-of-wysiwyg#comment-323" title="full comment on: Hacker Culture and the Fear of WYSIWYG">read more</a></li>
</ul>
</div>
</div>
<div id="bar"> </div>
<!-- Piwik, Open Source Analytics,
let’s not give Google more data then necessary! Eric -->
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://var.schr.fr/piwik/" : "http://var.schr.fr/piwik/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 2);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="http://var.schr.fr/piwik/piwik.php?idsite=2" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Tracking Code -->
<!--[if !(lt IE 8)]><!-->
<script type="text/javascript">
(function(){var e=document.createElement("script");e.type="text/javascript";e.async=true;e.src=document.location.protocol+"//d1agz031tafz8n.cloudfront.net/thedaywefightback.js/widget.min.js";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)})()
</script>
<!--<![endif]-->
</body>
</html>