すごく手間と時間がかかるのでもう二度とやりたくない。デビアン化しようかと真剣に考えた。でも無事導入できたので、純正玄箱のまま突っ走る。非力な純正玄箱で、コンパイル済みpackageもない。それぞれの./configure make make install が最低20分以上かかる。泣きそうだ。
ImageMagick
各種画像を統一的APIで簡単に扱えるパッケージ。各種画像ってのがくせ者。標準だとBMPやGIFからPNGへ変換しか出来ないと思ってイイ。
必要なもの
ソースコード以外で必須なもの。
- 時間:とてもたくさん。こんかいは6時間くらい。
- GNU SCREEN:時間かかるから途中で寝落ちしても大丈夫なように。複数同時にやらないと我慢できない。
- 根性 :./configure失敗してもめげない
ソースコード
- ImageMagick本体*1
- zlib最新版(念のため)
- JPEG関連
- JPEG2000関連
- unzip:JPEG2000パーケージ展開にUnZipが必要でした。
- TIFF関連
- PNG関連
最初は画像ライブラリを入れた。
ImageMagickをビルドしてみたけれど、やっぱりひたいおうだらけ。しかも、モジュール足りなくてMakeが止まる。
Zlibを入れておく
なんか画像圧縮に必要らしい。
wget http://www.zlib.net/zlib-1.2.3.tar.gz tar zxvf zlib-1.2.3.tar.gz cd zlib-1.2.3 ./configure make sudo make install
まずはJPEGから
コマンドシンプル。なのに、やたら時間がかかります。
JPEG関連
$cd /usr/local/src $wget http://www.ijg.org/files/jpegsrc.v6b.tar.gz $tar zxvf jpegsrc.v6b.tar.gz $cd jpeg-6b/ $./configure --enable-shared $make $sudo make install
PNG関連
LibPNGの本家; http://www.libpng.org/pub/png/libpng.html
curl -O http://prdownloads.sourceforge.net/libpng/libpng-1.2.34.tar.gz?download cd libpng-1.2.34 ./configure make -j2 sudo make install
TIFF関連
本家? http://www.linuxfromscratch.org/blfs/view/svn/general/libtiff.html
wget ftp://ftp.remotesensing.org/libtiff/tiff-3.8.2.tar.gz tar zxvf tiff-3.8.2.tar.gz cd tiff-3.8.2 ./configure make -j2 sudo make install
JPEG-2000関連
jpegとjpeg-2000でライブラリが違うので注意した。
本家:http://www.ece.uvic.ca/~mdadams/jasper/
wget http://www.ece.uvic.ca/~mdadams/jasper/software/jasper-1.900.1.zip tar zxvf jasper-1.900.1.zip gzip: stdin has more than one entry--rest ignored tar: Child returned status 2 tar: Error exit delayed from previous errors unzip jasper-1.900.1.zip bash: unzip: command not found
そうかZIPだ、GZIPじゃない。
純正のそのままの素の玄箱にはzip/unzipが入ってない。
じゃあGunzipでなんとかしようか。。。。ん?Gunzipってバイナリじゃない。
解凍できないので、Windowsから解凍して持って行くことも有りだが、今後のこと考えて(コンパイルし直し)また使うときが来るハズ。
Zip/unzipを作ることにする。
Zip本家: http://www.info-zip.org/UnZip.html *2
tug.ctan.org (US) [FROZEN]
ftp.tex.ac.uk (UK) [FROZEN]
ftp.dante.de (Germany) [FROZEN]
ってどこもFROZENじゃん。sourceforgeにLATESTが在るそうだ。
sourceforgeにzip30.zipがあった。ZIP/UNZIPがつかえない人に対するジョークだろう。
tar.gz版を入手
wget http://jaist.dl.sourceforge.net/sourceforge/infozip/zip30.tar.gz wget http://jaist.dl.sourceforge.net/sourceforge/infozip/unzip552.tar.gz tar zxvf zip30.tar.gz tar zxvf unzip552.tar.gz cd zip30 make -f unix/Makefile generic make -f unix/Makefile install cd ../unzip552 make -f unix/Makefile generic make -f unix/Makefile install
Makeが特殊でした。Windows版・MAC版などが入ったpackageなので、必要Makefileを指定するようです。
JPEG2000をインストールやり直し。
ZIPが解凍できなくて躓いたので、再度やり直し。
wget http://www.ece.uvic.ca/~mdadams/jasper/software/jasper-1.900.1.zip unzip jasper-1.900.1.zip cd jasper-1.900.1 ./configure make..... ...失敗エラー
仕方ないので古いバージョンを
wget http://www.ece.uvic.ca/~mdadams/jasper/software/jasper-1.701.0.zip unzip jasper-1.701.0.zip cd jasper-1.701.0 ./configure make sudo make install
無事終了。
巨大戦艦を造ります。
ImageMagickのコンパイルに
ImageMagickの本家は http://www.imagemagick.org/
さて、ここまでで部品を作りました。ここからこの部品を組み合わせて巨大戦艦です。
本家サイトに、binaryリリースとか見えるけど見ないことにする。
wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz tar zxvf ImageMagick.tar.gz cd ImageMagick-6.4.9-2 ./configure ----------------<中略>-------------------------------------------------- checking for FlashPIX... checking fpxlib.h usability... no checking fpxlib.h presence... no checking for fpxlib.h... no checking for FPX_OpenImageByFilename in -lfpx... no checking if FlashPIX package is complete... no ----------------<中略>-------------------------------------------------- checking for JPEG Version 2... checking jasper/jasper.h usability... no checking jasper/jasper.h presence... no checking for jasper/jasper.h... no checking for jas_stream_fopen in -ljasper... yes checking if JPEG version 2 support package is complete... no -- some components failed test ----------------<中略>-------------------------------------------------- Option Value ------------------------------------------------------------------------------- Shared libraries --enable-shared=yes yes Static libraries --enable-static=yes yes Module support --with-modules=yes yes GNU ld --with-gnu-ld=yes yes Quantum depth --with-quantum-depth=16 16 High Dynamic Range Imagery --enable-hdri=no no Delegate Configuration: BZLIB --with-bzlib=yes yes Autotrace --with-autotrace=no no DJVU --with-djvu=yes no DPS --with-dps=yes no FlashPIX --with-fpx=yes no FontConfig --with-fontconfig=no no FreeType --with-freetype=yes no GhostPCL None pcl6 (unknown) GhostXPS None gxps (unknown) Ghostscript None gs (unknown) result_ghostscript_font_dir='none' Ghostscript fonts --with-gs-font-dir=default Ghostscript lib --with-gslib=yes no Graphviz --with-gvc=yes no JBIG --with-jbig=yes no JPEG v1 --with-jpeg=yes yes JPEG-2000 --with-jp2=yes no (failed tests) LCMS --with-lcms=yes no LQR --with-lqr=yes no Magick++ --with-magick-plus-plus=yes yes OpenEXR --with-openexr=yes no PERL --with-perl=yes /usr/local/bin/perl PNG --with-png=yes yes RSVG --with-rsvg=no no TIFF --with-tiff=yes no (failed tests) Windows fonts --with-windows-font-dir= WMF --with-wmf=yes no X11 --with-x= no X11 --with-x= no XML --with-xml=no no ZLIB --with-zlib=yes yes X11 Configuration: X_CFLAGS = X_PRE_LIBS = X_LIBS = X_EXTRA_LIBS = Options used to compile and link: PREFIX = /usr/local EXEC-PREFIX = /usr/local VERSION = 6.4.9 CC = gcc CFLAGS = -g -O2 -Wall -W -pthread MAGICK_CFLAGS = -g -O2 -Wall -W -pthread CPPFLAGS = -I/usr/local/include/ImageMagick PCFLAGS = DEFS = -DHAVE_CONFIG_H LDFLAGS = MAGICK_LDFLAGS = -L/usr/local/lib LIBS = -lMagickCore -ljpeg -lbz2 -lz -lm -lpthread CXX = g++ CXXFLAGS = -g -O2 -Wall -W -pthread
TIFF/JPEG200今回使いたかったものが・・・無理。
サポート無しでconfigureされた
JPEG-2000 --with-jp2=yes no (failed tests) TIFF --with-tiff=yes no (failed tests)
なぜか意図したとおりにいかない。
救世主ブログ現る。
http://blog.teachat.org/archives/4081552.html
ImageMagickのインストール
# cd /usr/local/src # wget --passive-ftp ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick-5.5.7-15.tar.gz # tar zxvf ImageMagick-5.5.7-15.tar.gz # cd ImageMagick-5.5.7 # setenv CPPFLAGS -I/usr/local/include # setenv LDFLAGS -L/usr/local/lib # ./configure --enable-lzw=yes |& tee configure.log--enable-lzwは多分GIFサポート。
Cシェルなのでsetenv。Bシェルの場合は変えること。
やってみた。そして、JPEGとTIFFをもう一度初めからMAKEし直してみた。
#JPEG unzip jasper-1.701.0.zip cd jasper-1.701.0 ./configure make sudo make install cd .. #TIFF tar zxvf tiff-3.8.2.tar.gz cd tiff-3.8.2 ./configure make sudo make install #ImageMagick tar zxvf ImageMagick.tar.gz cd ImageMagick-6.4.9-2 export CPPFLAGS="-I/usr/local/include" export LDFLAGS="-L/usr/local/lib" ./configure --enable-lzw=yes --with-jp2=yes --with-tiff=yes ################中略#######################3 Host system type: powerpc-unknown-linux-gnu Build system type: powerpc-unknown-linux-gnu Option Value ------------------------------------------------------------------------------- Shared libraries --enable-shared=yes yes Static libraries --enable-static=yes yes Module support --with-modules=yes yes GNU ld --with-gnu-ld=yes yes Quantum depth --with-quantum-depth=16 16 High Dynamic Range Imagery --enable-hdri=no no Delegate Configuration: BZLIB --with-bzlib=yes yes Autotrace --with-autotrace=no no DJVU --with-djvu=yes no DPS --with-dps=yes no FlashPIX --with-fpx=yes no FontConfig --with-fontconfig=no no FreeType --with-freetype=yes no GhostPCL None pcl6 (unknown) GhostXPS None gxps (unknown) Ghostscript None gs (unknown) result_ghostscript_font_dir='none' Ghostscript fonts --with-gs-font-dir=default Ghostscript lib --with-gslib=yes no Graphviz --with-gvc=yes no JBIG --with-jbig=yes no JPEG v1 --with-jpeg=yes yes JPEG-2000 --with-jp2=yes yes LCMS --with-lcms=yes no LQR --with-lqr=yes no Magick++ --with-magick-plus-plus=yes yes OpenEXR --with-openexr=yes no PERL --with-perl=yes /usr/local/bin/perl PNG --with-png=yes yes RSVG --with-rsvg=no no TIFF --with-tiff=yes yes Windows fonts --with-windows-font-dir= WMF --with-wmf=yes no X11 --with-x= no XML --with-xml=no no ZLIB --with-zlib=yes yes X11 Configuration: X_CFLAGS = X_PRE_LIBS = X_LIBS = X_EXTRA_LIBS = Options used to compile and link: PREFIX = /usr/local EXEC-PREFIX = /usr/local VERSION = 6.4.9 CC = gcc CFLAGS = -g -O2 -Wall -W -pthread MAGICK_CFLAGS = -g -O2 -Wall -W -pthread CPPFLAGS = -I/usr/local/include/ImageMagick PCFLAGS = DEFS = -DHAVE_CONFIG_H LDFLAGS = MAGICK_LDFLAGS = -L/usr/local/lib LIBS = -lMagickCore -ltiff -ljpeg -lbz2 -lz -lm -lpthread CXX = g++ CXXFLAGS = -g -O2 -Wall -W -pthread #おおおおおおお make sudo make install
Historyを見てみると、TIFFをコンパイルしてMake installを忘れていた模様。あはは。
早速テスト
takuya$ identify -list format Format Module Mode Description ------------------------------------------------------------------------------- A* RAW rw+ Raw alpha samples AI PDF rw- Adobe Illustrator CS2 ART* ART rw- PFS: 1st Publisher Clip Art ARW DNG r-- Sony Alpha Raw Image Format AVI* AVI r-- Microsoft Audio/Visual Interleaved AVS* AVS rw+ AVS X image B* RAW rw+ Raw blue samples BGR* RGB rw+ Raw blue, green, and red samples BMP* BMP rw- Microsoft Windows bitmap image BMP2* BMP -w- Microsoft Windows bitmap image v2 BMP3* BMP -w- Microsoft Windows bitmap image v3 BRF* BRAILLE -w- BRF ASCII Braille format BRG* RGB rw+ Raw blue, red, and green samples C* RAW rw+ Raw cyan samples CAPTION* CAPTION r-- Image caption CIN* CIN rw+ Cineon Image File CIP* CIP -w- Cisco IP phone image format CLIP* CLIP -w+ Image Clip Mask CMYK* CMYK rw+ Raw cyan, magenta, yellow, and black samples CMYKA* CMYK rw+ Raw cyan, magenta, yellow, black, and alpha samples CR2 DNG r-- Canon Digital Camera Raw Image Format CRW DNG r-- Canon Digital Camera Raw Image Format CUR* CUR rw- Microsoft icon CUT* CUT r-- DR Halo DCM* DCM r-- Digital Imaging and Communications in Medicine image DICOM is used by the medical community for images like X-rays. The specification, "Digital Imaging and Communications in Medicine (DICOM)", is available at http://medical.nema.org/. In particular, see part 5 which describes the image encoding (RLE, JPEG, JPEG-LS), and supplement 61 which adds JPEG-2000 encoding. DCR DNG r-- Kodak Digital Camera Raw Image File DCX* PCX rw+ ZSoft IBM PC multi-page Paintbrush DDS* DDS r-- Microsoft DirectDraw Surface DFONT* TTF --- Multi-face font package DNG DNG r-- Digital Negative DOT DOT --- Graphviz DPS DPS --- Display Postscript Interpreter DPX* DPX rw+ SMPTE 268M-2003 (DPX 2.0) Digital Moving Picture Exchange Bitmap, Version 2.0. See SMPTE 268M-2003 specification at http://www.smtpe.org EPDF PDF rw- Encapsulated Portable Document Format EPI PS rw- Encapsulated PostScript Interchange format EPS PS rw- Encapsulated PostScript EPS2* PS2 -w- Level II Encapsulated PostScript EPS3* PS3 -w+ Level III Encapsulated PostScript EPSF PS rw- Encapsulated PostScript EPSI PS rw- Encapsulated PostScript Interchange format EPT EPT rw- Encapsulated PostScript with TIFF preview EPT2 EPT rw- Encapsulated PostScript Level II with TIFF preview EPT3 EPT rw+ Encapsulated PostScript Level III with TIFF preview ERF DNG r-- Epson RAW Format FAX* FAX rw+ Group 3 FAX FAX machines use non-square pixels which are 1.5 times wider than they are tall but computer displays use square pixels, therefore FAX images may appear to be narrow unless they are explicitly resized using a geometry of "150x100%". FITS* FITS rw- Flexible Image Transport System FRACTAL* PLASMA r-- Plasma fractal image FTS* FTS rw- Flexible Image Transport System G* RAW rw+ Raw green samples G3* FAX rw- Group 3 FAX GBR* RGB rw+ Raw green, blue, and red samples GIF* GIF rw+ CompuServe graphics interchange format GIF87* GIF rw- CompuServe graphics interchange format (version 87a) GRADIENT* GRADIENT r-- Gradual linear passing from one shade to another GRAY* GRAY rw+ Raw gray samples GRB* RGB rw+ Raw green, red, and blue samples HISTOGRAM* HISTOGRAM -w- Histogram of the image HTM* HTML -w- Hypertext Markup Language and a client-side image map HTML* HTML -w- Hypertext Markup Language and a client-side image map ICB* TGA rw+ Truevision Targa image ICO* ICON rw+ Microsoft icon ICON* ICON rw- Microsoft icon INFO INFO -w+ The image format and characteristics INLINE* INLINE r-- Base64-encoded inline images IPL* IPL rw+ IPL Image Sequence ISOBRL* BRAILLE -w- ISO/TR 11548-1 format JNG* PNG rw- JPEG Network Graphics See http://www.libpng.org/pub/mng/ for details about the JNG format. JP2* JP2 rw- JPEG-2000 File Format Syntax JPC* JPC rw- JPEG-2000 Code Stream Syntax JPEG* JPEG rw- Joint Photographic Experts Group JFIF format (62) JPG* JPEG rw- Joint Photographic Experts Group JFIF format JPX* JPX rw- JPEG-2000 File Format Syntax K* RAW rw+ Raw black samples K25 DNG r-- Kodak Digital Camera Raw Image Format KDC DNG r-- Kodak Digital Camera Raw Image Format LABEL* LABEL r-- Image label M* RAW rw+ Raw magenta samples M2V MPEG rw+ MPEG Video Stream M4V MPEG rw+ Raw MPEG-4 Video MAP* MAP rw- Colormap intensities and indices MAT MAT rw+ MATLAB image format MATTE* MATTE -w+ MATTE format MIFF* MIFF rw+ Magick Image File Format MNG* PNG rw+ Multiple-image Network Graphics (libpng 1.2.34) See http://www.libpng.org/pub/mng/ for details about the MNG format. MONO* MONO rw- Raw bi-level bitmap MOV MPEG rw+ MPEG Video Stream MP4 MPEG rw+ MPEG-4 Video Stream MPC* MPC rw+ Magick Persistent Cache image format MPEG MPEG rw+ MPEG Video Stream MPG MPEG rw+ MPEG Video Stream MRW DNG r-- Sony (Minolta) Raw Image File MSL* MSL --- Magick Scripting Language MSVG SVG -w+ ImageMagick's own SVG internal renderer MTV* MTV rw+ MTV Raytracing image format MVG* MVG rw- Magick Vector Graphics NEF DNG r-- Nikon Digital SLR Camera Raw Image File NULL* NULL rw- Constant image of uniform color O* RAW rw+ Raw opacity samples ORF DNG r-- Olympus Digital Camera Raw Image File OTB* OTB rw- On-the-air bitmap OTF* TTF --- Open Type font PAL* UYVY rw- 16bit/pixel interleaved YUV PALM* PALM rw+ Palm pixmap PAM* PNM rw+ Common 2-dimensional bitmap format PATTERN* PATTERN r-- Predefined pattern PBM* PNM rw+ Portable bitmap format (black and white) PCD* PCD rw- Photo CD PCDS* PCD rw- Photo CD PCL PCL rw- Printer Control Language PCT* PICT rw- Apple Macintosh QuickDraw/PICT PCX* PCX rw- ZSoft IBM PC Paintbrush PDB* PDB rw+ Palm Database ImageViewer Format PDF PDF rw+ Portable Document Format PDFA PDF rw+ Portable Document Archive Format PEF DNG r-- Pentax Electronic File PFA* TTF --- Postscript Type 1 font (ASCII) PFB* TTF --- Postscript Type 1 font (binary) PFM* PFM rw+ Portable float format PGM* PNM rw+ Portable graymap format (gray scale) PGX* PGX r-- JPEG-2000 VM Format PICON* XPM rw- Personal Icon PICT* PICT rw- Apple Macintosh QuickDraw/PICT PIX* PIX r-- Alias/Wavefront RLE image format PJPEG* JPEG rw- Progessive Joint Photographic Experts Group JFIF PLASMA* PLASMA r-- Plasma fractal image PNG* PNG rw- Portable Network Graphics (libpng 1.2.34) See http://www.libpng.org/ for details about the PNG format. PNG24* PNG rw- opaque 24-bit RGB (zlib 1.2.3) PNG32* PNG rw- opaque or transparent 32-bit RGBA PNG8* PNG rw- 8-bit indexed with optional binary transparency PNM* PNM rw+ Portable anymap PPM* PNM rw+ Portable pixmap format (color) PREVIEW* PREVIEW -w- Show a preview an image enhancement, effect, or f/x PS PS rw+ PostScript PS2* PS2 -w+ Level II PostScript PS3* PS3 -w+ Level III PostScript PSD* PSD rw+ Adobe Photoshop bitmap PTIF* TIFF rw+ Pyramid encoded TIFF PWP* PWP r-- Seattle Film Works R* RAW rw+ Raw red samples RADIAL-GRADIENT* GRADIENT r-- Gradual radial passing from one shade to another RAF DNG r-- Fuji CCD-RAW Graphic File RAS* SUN rw+ SUN Rasterfile RBG* RGB rw+ Raw red, blue, and green samples RGB* RGB rw+ Raw red, green, and blue samples RGBA* RGB rw+ Raw red, green, blue, and alpha samples RGBO* RGB rw+ Raw red, green, blue, and opacity samples RLA* RLA r-- Alias/Wavefront image RLE* RLE r-- Utah Run length encoded image SCR* SCR r-- ZX-Spectrum SCREEN$ SCT* SCT r-- Scitex HandShake SFW* SFW r-- Seattle Film Works SGI* SGI rw+ Irix RGB image SHTML* HTML -w- Hypertext Markup Language and a client-side image map SR2 DNG r-- Sony Raw Format 2 SRF DNG r-- Sony Raw Format STEGANO* STEGANO r-- Steganographic image SUN* SUN rw+ SUN Rasterfile SVG SVG -w+ Scalable Vector Graphics SVGZ SVG -w+ Compressed Scalable Vector Graphics TEXT* TXT rw- Text TGA* TGA rw+ Truevision Targa image THUMBNAIL* THUMBNAIL -w+ EXIF Profile Thumbnail TIFF* TIFF rw+ Tagged Image File Format (LIBTIFF, Version 3.8.2) TIFF64* TIFF --- Tagged Image File Format (64-bit) (LIBTIFF, Version 3.8.2) TILE* TILE r-- Tile image with a texture TIM* TIM r-- PSX TIM TTC* TTF --- TrueType font collection TTF* TTF --- TrueType font TXT* TXT rw- Text UBRL* BRAILLE -w- Unicode Text format UIL* UIL -w- X-Motif UIL table UYVY* UYVY rw- 16bit/pixel interleaved YUV VDA* TGA rw+ Truevision Targa image VICAR* VICAR rw- VICAR rasterfile format VID* VID rw+ Visual Image Directory VIFF* VIFF rw+ Khoros Visualization image VST* TGA rw+ Truevision Targa image WBMP* WBMP rw- Wireless Bitmap (level 0) image WMV MPEG rw+ Windows Media Video WPG* WPG r-- Word Perfect Graphics X3F DNG r-- Sigma Camera RAW Picture File XBM* XBM rw- X Windows system bitmap (black and white) XC* XC r-- Constant image uniform color XCF* XCF r-- GIMP image XPM* XPM rw- X Windows system pixmap (color) XPS XPS r-- Microsoft XML Paper Specification XV* VIFF rw+ Khoros Visualization image Y* RAW rw+ Raw yellow samples YCbCr* YCbCr rw+ Raw Y, Cb, and Cr samples YCbCrA* YCbCr rw+ Raw Y, Cb, Cr, and alpha samples YUV* YUV rw- CCIR 601 4:1:1 or 4:2:2 * native blob support
行けたよ!!
6時間。長きにわたる戦いに打ち勝ちました。
早速PERLもやってみる。
複数ページのTIFFを一枚毎のJPEGに分割する。
#!/usr/bin/env perl use utf8; use strict; use warnings; use Image::Magick; my $p = new Image::Magick; #普通のTIFF #複数ページのTIFF $p->Read("20090210104729839.tif"); for my $i ( @$p ) { $i->Write("by_perl_$i.jpg"); }
分割されました。
by_perl_Image::Magick=SCALAR(0x81dc900).jpg by_perl_Image::Magick=SCALAR(0x81dc908).jpg by_perl_Image::Magick=SCALAR(0x81dc918).jpg by_perl_Image::Magick=SCALAR(0x81dc920).jpg
これで複合機のTIFFファイルを一括処理できる。
複合機がファックスやメールやスキャナー玄箱に保存してくれる。
保存してくれるのはよいのですが、社外からのFAXが全部TIFFでしかも複数枚。
探すのが面倒だから、これで一括でJPGに変換することにします。
参考文献
http://jo1upk.blogdns.net/linux/?%E7%8E%84%E7%AE%B1%2FImageMagick
http://hirotyanteikoku.cocolog-nifty.com/cocolog/2005/04/imagemagick_f36d.html
http://blog.teachat.org/archives/4081552.html
http://www.fukuoka-edu.ac.jp/~kanamitu/install/sol26/ImageMagick-4.0.7.txt