[CENTOS] I tried to introduce the block diagram generation tool blockdiag

Introduction

■ What is blockdiag?

From the official website http://blockdiag.com/ja/index.html

The blockdiag series is a group of image generation tools that generate images such as block diagrams from simple text.

■ What I tried this time

"Generate image file from text-based definition file" I tried this.

■ Reference site

・ From the official website, for CentOS 6.2 http://blockdiag.com/ja/blockdiag/introduction.html#centos-6-2

・ From the official website, execution method and font settings http://blockdiag.com/ja/blockdiag/introduction.html#id10

▽ Other You can draw a figure without a mouse! I fell in love with blockdiag http://d.hatena.ne.jp/torazuka/20110620/blockdiag

Introduction

■ Environment

AWS EC2(CentOS 6.5) Python 2.6.6

■ Installation

# yum install python-setuptools python-imaging ipa-gothic-fonts
# easy_install blockdiag

▽ From error handling 2

# yum install python-devel zlib-devel libjpeg-devel

▽ From error handling 4

# yum install freetype-devel.x86_64

▽ From error handling 1

# easy_install pillow
# easy_install webcolors
# easy_install funcparserlib

▽ From error handling 3

# easy_install -U reportlab==2.5

▽ Installation confirmation (python package)

# pip freeze | grep -i "blockdiag\|pillow\|webcolors\|funcparserlib"

Setting

■ Font

▽ When specifying the font at runtime

$ blockdiag -f /usr/share/fonts/ipa-gothic/ipag.ttf simple.diag

▽ When defining in $ HOME / .blockdiagrc

$ vi $HOME/.blockdiagrc
--------------------
[blockdiag]
fontpath = /usr/share/fonts/ipa-gothic/ipag.ttf

Operation check

Run the blockdiag command to generate a block diagram.

■ Move directory

First, move to the document root of the web server that can display the image to be created

# cd /var/www/html

■ From a simple block diagram

http://blockdiag.com/ja/blockdiag/examples.html#simple-diagram

# vi simple.diag
-----------------
blockdiag {
   A -> B -> C -> D;
   A -> E -> F -> G;
}

・ Generate a block diagram

# blockdiag simple.diag
# blockdiag -Tsvg simple.diag
# blockdiag -Tpdf simple.diag
* From the top, PNG format, SVG format, PDF format

・ Check from the browser http://example.com/simple.png 20141006_blockdiag_sample01.png

http://example.com/simple.svg 20141006_blockdiag_sample02.png

http://example.com/simple.pdf 20141006_blockdiag_sample03.png

■ From the use of Japanese

http://blockdiag.com/ja/blockdiag/examples.html#mutlilingualization

# vi nippon.diag
-----------------
blockdiag admin {
   // Set M17N text using label property.
   A [label = "Ki"];
   B [label = "Accepted"];
   C [label = "Turn"];
   D [label = "Conclusion"];

   A -> B -> C -> D;

   // Use M17N text directly (need to quote).
spring->summer->autumn->winter;

   // Use M17N text including symbol characters (need to quote).
   "Spring is dawn" -> "summer=Night" -> "autumn.evening" -> "winter&be making an effort";
}

・ Generate a block diagram

# blockdiag nippon.diag
# blockdiag -Tsvg nippon.diag
# blockdiag -Tpdf nippon.diag
* From the top, PNG format, SVG format, PDF format

・ Check from the browser

http://example.com/nippon.png 20141006_blockdiag_sample04.png

http://example.com/nippon.svg 20141006_blockdiag_sample05.png

http://example.com/nippon.pdf 20141006_blockdiag_sample06.png

Supplement

■ Error handling 1

-If the following error is output when executing the diag command

# blockdiag simple.diag
--------------------
Traceback (most recent call last):
  File "/usr/bin/blockdiag", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 2655, in <module>
    working_set.require(__requires__)
  File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 648, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 546, in resolve
    raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: Pillow

-Check that pillow is not installed

# pip freeze | grep -i "pillow\|webcolors\|funcparserlib"
* Pip is a package management system in Python.

・ Pillow installation

# easy_install pillow

▽ The following error after introducing pillow

pkg_resources.DistributionNotFound: webcolors

・ Installation of web colors

# easy_install webcolors

▽ The following error after introducing web colors

pkg_resources.DistributionNotFound: funcparserlib

・ Installation of funcparserlib

# easy_install funcparserlib

・ Introduction confirmation

# pip freeze | grep -i "pillow\|webcolors\|funcparserlib\|reportlab"
Pillow==2.6.0
funcparserlib==0.3.6
webcolors==1.4

■ Error handling 2

▽ When the following error is output during pillow installation

(abridgement)
_imaging.c:3570: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘init_imaging’
error: Setup script exited with error: command 'gcc' failed with exit status 1

・ Introduce the following packages (from the forum)

# yum install python-devel zlib-devel libjpeg-devel
------
zlib-devel-1.2.3-29.el6.x86_64
libjpeg-turbo-devel-1.2.1-3.el6_5.x86_64
python-devel-2.6.6-52.el6.x86_64

・ Countermeasure, pass the following path (from the forum)

# export CFLAGS=-Qunused-arguments
# export CPPFLAGS=-Qunused-arguments

-Execute the installation command again

# easy_install pillow

■ Error handling 3

▽ If you cannot create a block diagram in PDF format

# blockdiag -Tpdf simple.diag
ERROR: unknown format: PDF

▽ Install reportlab

easy_install -U reportlab==2.5
# python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)

>>> import reportlab
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/reportlab-3.1.8-py2.6-linux-x86_64.egg/reportlab/__init__.py", line 11, in <module>
    raise ImportError("""reportlab requires Python 2.7+ or 3.3+; 3.0-3.2 are not supported.""")
ImportError: reportlab requires Python 2.7+ or 3.3+; 3.0-3.2 are not supported.

■ Error handling 4

▽ When trying to create a sample block diagram including Japanese

# blockdiag nippon.diag
ERROR: The _imagingft C module is not installed

▽ Reference site [python] When PIL gives an import error of _imagingft http://d.hatena.ne.jp/pashango_p/20110919/1316408103

The point is that FreeType2 was not installed when compiling PIL. For Linux (OpenSuse), install the "freetype2-devel" package and then install PIL to solve the problem.

▽ Install freetype-devel

# yum install freetype-devel.x86_64

▽ Uninstall / install PIL (From the official website) Reinstalling the PIL package

# easy_install -m PIL
# \rm -rf /usr/lib/python2.6/site-packages/PIL-1.1.7-py2.6-linux-x86_64.egg

# easy_install PIL

▽ Reinstall pillow

# easy_install -m pillow
# \rm -rf /usr/lib/python2.6/site-packages/Pillow-2.6.0-py2.6-linux-x86_64.egg

# easy_install pillow

▽ After the above settings, when the command was executed again, it was successfully output in PDF format.

# blockdiag nippon.diag

# ls -l nippon.pdf
-rw-r--r--1 root root 20415 October 6 16:47 2014 nippon.pdf

That's it.

Recommended Posts

I tried to introduce the block diagram generation tool blockdiag
Continuation: I tried to introduce the block diagram generation tool blockdiag
I tried to introduce Pylint
I tried to move the ball
I tried to estimate the interval.
I tried to summarize the umask command
I tried to recognize the wake word
I tried the OSS visualization tool, superset
I tried to summarize the graphical modeling.
I tried to estimate the pi stochastically
I tried to touch the COTOHA API
I tried web scraping to analyze the lyrics.
I tried to optimize while drying the laundry
I tried to save the data with discord
I tried to touch the API of ebay
I tried to correct the keystone of the image
Qiita Job I tried to analyze the job offer
LeetCode I tried to summarize the simple ones
I tried to implement the traveling salesman problem
I tried to predict the price of ETF
I tried to vectorize the lyrics of Hinatazaka46!
I tried to debug.
I tried to paste
I tried to learn the sin function with chainer
I tried to graph the packages installed in Python
When I tried to introduce python3 to atom, I got stuck
I tried to detect the iris from the camera image
I tried to summarize the basic form of GPLVM
I tried to touch the CSV file with Python
I tried to predict the J-League match (data analysis)
I tried to solve the soma cube with python
I tried to approximate the sin function using chainer
[TensorFlow] I tried to introduce AI to rolling stock iron
I tried to put pytest into the actual battle
[Python] I tried to graph the top 10 eyeshadow rankings
I tried to visualize the spacha information of VTuber
I tried to erase the negative part of Meros
I tried to solve the problem with Python Vol.1
I tried to simulate the dollar cost averaging method
I tried to redo the non-negative matrix factorization (NMF)
I tried to identify the language using CNN + Melspectogram
I tried to notify the honeypot report on LINE
I tried to complement the knowledge graph using OpenKE
I tried to classify the voices of voice actors
I tried to draw a configuration diagram using Diagrams
I tried to compress the image using machine learning
I tried to summarize the string operations of Python
[Python] I tried to summarize the array, dictionary generation method, loop method, list comprehension notation
I tried to find the entropy of the image with python
I tried to find out the outline about Big Gorilla
I tried porting the code written for TensorFlow to Theano
[Horse Racing] I tried to quantify the strength of racehorses
I tried to simulate how the infection spreads with Python
I tried to analyze the whole novel "Weathering with You" ☔️
[First COTOHA API] I tried to summarize the old story
I tried to get the location information of Odakyu Bus
I tried to learn PredNet
I tried to find the average of the sequence with TensorFlow
I tried to notify the train delay information with LINE Notify
I tried to simulate ad optimization using the bandit algorithm.
I tried to organize SVM.