2007年2月28日水曜日

ImageMagick

写真の画像を一括変換してPDFにするとします。ImageMagickを使って、例えばデジカメで取った写真photo1.jpg, photo2.jpg, ..., photo10.jpgのコントラストを上げて、色を調整して、1つのPDFファイルにするコマンドは以下の通り:
> convert -adjoin -sigmoidal-contrast 3,0% -normalize photo<1-10>.jpg out.pdf


convert -thumbnail 100 'out.pdf[5]'
なんて書き方で、pdfの6ページ目(0 origin)だけを取り出してthumbnailをつくるなんてこともできます。

2007年2月20日火曜日

Fat Jar: Jarファイルの中にJarを埋め込む

Fat Jar Eclipse Plug-In

Javaで開発していて、他のライブラリのアーカイブ(Jar)を使っている場合、自分のプログラムもJarとして配布するときに、manifestファイルに適切に外部のJarへのreferenceを書いておかないと正しく動作しません。

通常は、classpathの設定を含めた実行スクリプトを一緒に配布することが多いみたいです。でも、スクリプトを用意するのは面倒ですよね。

そんな煩わしさを取り除くのが、Fat Jar。Jarの中にJarファイルを埋め込んでプロジェクト全体を1つのファイルとすることができます。

Fat Jarは、通常は、外部で参照しているJarを展開してJarの中に埋め込むのですが、One-Jarオプションを選ぶと、jarファイルを展開せずにそのままjarの中に埋め込みます。こちらの方が、構成内容がよくわかります。

Fat Jarを使うと、今まで、
java -cp lib/somelibrary.jar -jar myprogram.jar
などとしていたところを、

java -jar myprogram.jar

と実行するだけでよくなります。意外と知らない人がいると思うので、紹介しました。おすすめです。

最近はJARの作り方も事情が変わっています。2008年8月 http://leoclock.blogspot.com/2008/08/jarjar.html

2007年2月17日土曜日

プログラム開発でよくある失敗

Visual Studio 2003 (vc7.1)から、Visual Studio 2005 (vc8)に乗り換えました。

ただ、この2つで使われるマルチスレッドのライブラリのversionが違っていて、vc7.1でビルドしたマルチスレッドを使うライブラリ(dll)を実行時に使ってしまうと、原因とは脈絡もないところでメモリ関連のエラーが出てデバッグに苦しみます。

そういうときは、
> dumpbin /dependents (dllのファイル)
で調べます。
Dump of file xerces-c_2_7D.dll

File Type: DLL

Image has the following dependencies:

WS2_32.dll
ADVAPI32.dll
KERNEL32.dll
MSVCR80D.dll

MSVCR80D.dll が、MSVCR71D.dllなどになっていたら危険信号。結局、普段良く使っている、BerkeleyDBとか、Xerces-C++とかを再コンパイル。

その点BoostライブラリのWindows版はよくできていて、対応するコンパイラでビルドされたライブラリがない場合はちゃんとこのライブラリがない、と実行時に指摘してくれます。dllを動的に読み込んでるからこそできる技。

でも、こんなの慣れた開発者じゃないとわからないよなぁ。。。。C++の教科書読んだって書いてないもの。xercesだって、BerkeleyDBだって、vc7.1でbuildされたdllを注意書きもなくしれっと配布しているし。。。やれやれ。

2007年2月15日木曜日

南隊員が帰ってきます 「エースの願い」

ウルトラマンエースをご存知ですか?主題歌の歌詞にもあるのですが、北斗と南の二人が揃って初めてウルトラマンA(エース)に変身できる、という設定でした。

でも、番組途中で、突然、南隊員は実は月星人だった!という理由で、月に帰ってしまい、その後は北斗が一人でウルトラマンとして戦うという展開になっていました。

北斗と南は想いを寄せ合っていたはずなのに、あんな別れで良かったの?とか、実は大人の事情で降板させられた?とか、いろいろすっきりしない部分が残っていたのです。

ウルトラマンメビウス 第44話 「エースの願い」

予告編によると、今週土曜日のウルトラマンメビウスでは、北斗と南が登場するようです。どのような形でこの二人のストーリーに解決をつけてくれるのか、期待しています。

似たような例として、村山由佳さんの「天使の卵」というとても悲しい話がありました。これも、10年後、「天使の梯子」という作品で、主人公の悲しみにうちひしがれた心の整理を付けさせてくれています。ウルトラマンエースはおよそ35年越し。世代をまたがっているんですね。

2007年2月14日水曜日

A Diary Written in English

Today, one of my friends decleared that he will start to write his diary in English. His decision stimulated me, so I also tried to write down this blog in English.

The most difficult thing I usually experience when writing down English sentences is the choice of words; For example, there are many expressions meaning, 'write' in English.

According to a thesaurus, synonyms of 'write' are:
write down, jot down, put down, note, take down, record, register, log, list, sign, scribble, scrawl, pencil, compose, draft, think up, formulate, compile, pen, dash off, produce, etc...

I am a non-native English speaker, so it is quite difficult to understand such slight differences between these words, e.g. How different 'write' and 'write down' are?

To learn these differences of words/phrases is important, because I know, in English, the use of repetition of the same word is not a good writing style. But, even in this short entry, I have already used many repeats of 'write down'. Nevertheless, appropriate replacements of such phrases never come up to me. I guess it is just because the amount of words and phrases I learned from people who speak English is not sufficient.

Recently, there are many audio sources of English speaking people available from PodCast, Google Video, You Tube, etc. I am happy to collect these materials to improve my English skills, because there were no easy method to get raw English voices a few years ago.

However, I get discouraged considering how fast my four-years-old son learns Japanese. Everyday, he speaks Japanese even if what he said contains some grammatical errors or misuse of words. Thus, I understood that 'do not get embarassed' is a key to efficiently learn to speak a new language.

Another key that I have already lost and cannot be achieved is good memories of a child; it is not only about my son, but in general, children remember well phrases once they have heared.

Here is an interesting story. It has been a daily routine for me and my wife to read some storybooks for my son before he sleeps. When he was two-years-old, he couldn't read any Japanese letters. As we continued to read through the same books for many times every night, one day, he said "I read this today." And, to our surprise, he started to read the contents of the book without seeing any characters, but what he read was almost correct. Maybe, he remembered what we read to him by making a strong connection to the paintings in the book.

Now, he has completely mastered hira-gana and kata-kana letters, so we never see his astonishing reading from memories. It is a little bit pity for me.

Conclusion; Since I have no such good memories, what I can is to keep learning English.

License

Creative Commons LicenseLeo's Chronicle by Taro L. Saito is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.1 Japan License.