Strict Standards: Non-static method Soojung::addReferer() should not be called statically in /home/lifthrasiir/sites/sapzil.info/soojung/settings.php on line 79

Warning: Cannot modify header information - headers already sent by (output started at /home/lifthrasiir/sites/sapzil.info/soojung/settings.php:79) in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Counter.class.php on line 63

Strict Standards: Non-static method Entry::getEntry() should not be called statically in /home/lifthrasiir/sites/sapzil.info/soojung/entry.php on line 51

Strict Standards: Non-static method Soojung::entryIdToFilename() should not be called statically in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Entry.class.php on line 182

Strict Standards: Non-static method Soojung::queryFilenameMatch() should not be called statically in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Soojung.class.php on line 55

Warning: fopen(contents/511/20050226095613.comment): failed to open stream: Permission denied in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 24

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 25

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 26

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 27

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 28

Warning: fclose() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 29

Warning: fopen(contents/511/20050226125121.comment): failed to open stream: Permission denied in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 24

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 25

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 26

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 27

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 28

Warning: fclose() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 29

Warning: fopen(contents/511/20050226130001.comment): failed to open stream: Permission denied in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 24

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 25

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 26

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 27

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 28

Warning: fclose() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 29

Warning: fopen(contents/511/20050226135249.comment): failed to open stream: Permission denied in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 24

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 25

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 26

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 27

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 28

Warning: fclose() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 29
TokigunStudio3 | 블로그: pydot과 PIL의 환상적인 만남

내용으로 바로 넘어 가기


TokigunStudio3

1 / 3283   


더 이상 이 블로그는 운영되지 않습니다. 새 블로그로 가 주세요.

pydot과 PIL의 환상적인 만남

2005/02/26 AM 06:19 | 개발/파이썬 | 4 comments | 0 trackbacks | AllBlog: vote, to pocket

당신은 얼마나 건전한가?라는 제목으로 올라 온 테스트(인가...)가 있었다. 이미지 수십 개를 보여 주면서 이미지맵으로 링크 따라 가게 하는데, 엉뚱한/응큼한 곳을 클릭하면 예상치 못한 페이지로 이동하는 특징을 가지고 있다. (혹자는 이들을 알아 내면 ㅂㅌ라는 소리를 하고 있다 -_-)

의외로 이런 식으로 상당히 많은 페이지들이 연결되어 있는 사이트들을 볼 수 있는데, 저거 보고 pydot 같은 걸로 보여 주면 어떨까 하고 밤 새도록 삽질한 끝에 그럭저럭 만족할 만한 결과를 얻어 냈다. (코드 자체는 저 사이트에 최적화되어 있지만 조금 고치면 다른 경우에도 적용할 수 있다. HTMLParser를 쓰게 만든다면야...)

* pydot이 뭔지 모르시는 분들을 위해... graphviz라고 오픈소스 그래프 시각화 프로그램이 있는데, (graph는 저기 나온 그림처럼 정점--vertex/node--과 그 정점을 잇는 간선--edge--으로 이루어진 도형..이라고 해야 하나. 암튼 수학이나 전산학 배우다 보면 다 나온다.) 이걸 파이썬 용으로 만들어 놓은 것이다. 예전에도 좀 써 봤는데 본격적으로(?) 써 본 건 이번이 처음이다. 그리고 PIL은 파이썬용 이미지 처리 라이브러리다.

그럼 그 삽질의 결과물을 보자:
- 지도 이미지 (열라 큼. 1.6MB. 18금 이미지도 다수 포함되어 있음.)
- 지도 보는 방법

놀랍게도 pydot이 HTML 형식의 포매팅을 지원하는 덕분에 처음에 "색깔 집어 넣고 어찌 어찌 해서 치환해야지" 하는 생각이 필요가 없어졌다. 하지만 멀티바이트 문자 들어 간 경로가 안 먹는 건 좀 (...) 이미지맵을 파싱해서 색깔 넣어 주는 것은 PIL로 했고, 나머지는 모두 pydot(graphviz)로 했는데 edge를 굵게 하는 게 뭔지 몰라서 한참 고생했었다.

하나 아까운 것은 아무리 해 봐도 node들이 좀 적당적당하게 배열되는 것을 찾을 수 없다는 것이다. fdp나 neato 같은 것도 몇 번 해 봤으나 너무 느리기도 하고 원하는 결과도 나오지 않아서 때려 쳤고, 결국 dot의 출력 결과를 그대로 쓰고 말았다. graphviz가 링크 탐색 순서 등등에 따라서 rank를 매겨 놓고 그 rank에 따라 위치를 정해서 벌어지는 일인데, 아무리 생각해도 왜 대각선 방향으로 위치를 정하는 옵션이 없는 지 모르겠다 -,.- (이거 있었으면 쓰는 건데... 으윽...) 암튼 그래서 그림이 좀 더 커져 버렸으니 양해 바란다 orz

뭐... 덕분에 pydot은 죽어라 건들어 댔으니 큰 수확이라 할 수 있겠다; (사실 이거 하면서 graphviz 레퍼런스도 수도 없이 들여다 봤다) 슬슬 자러 가야 겠다. (...)


한참 자고 일어 나서 덧붙임:
소스 코드를 공개한다. (뭐 볼 만한 건 하나도 없지만) 일단 grep -r 명령(나 같이 grep이 없는 사람은 winglet.py를 써도 된다)으로 파일을 긁어 모은 후, mapofmaze.py를 실행시켜서 이미지를 만든다. 당연하지만 파이썬, pydot, graphviz, PIL은 필수 -_-; 세세한 설정은 알아서 하시길 바란다.

TrackBack URL: http://sapzil.info/soojung/trackback.php?blogid=511

Comment: ()


Warning: fopen(contents/511/20050226095613.comment): failed to open stream: Permission denied in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 39

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 41

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 42

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 43

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 44

Warning: filesize(): stat failed for contents/511/20050226095613.comment in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 45

Warning: fread() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 45

Warning: fclose() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 46

Comment: ()


Warning: fopen(contents/511/20050226125121.comment): failed to open stream: Permission denied in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 39

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 41

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 42

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 43

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 44

Warning: filesize(): stat failed for contents/511/20050226125121.comment in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 45

Warning: fread() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 45

Warning: fclose() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 46

Comment: ()


Warning: fopen(contents/511/20050226130001.comment): failed to open stream: Permission denied in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 39

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 41

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 42

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 43

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 44

Warning: filesize(): stat failed for contents/511/20050226130001.comment in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 45

Warning: fread() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 45

Warning: fclose() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 46

Comment: ()


Warning: fopen(contents/511/20050226135249.comment): failed to open stream: Permission denied in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 39

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 41

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 42

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 43

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 44

Warning: filesize(): stat failed for contents/511/20050226135249.comment in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 45

Warning: fread() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 45

Warning: fclose() expects parameter 1 to be resource, boolean given in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Comment.class.php on line 46

Copyright (c) 1995-2005, Kang Seonghoon (Tokigun).