attachment_fu

簡単に画像を扱えるプラグインプラグイン自身のインストールは超簡単。

$ script/plugin install http://svn.techno-weenie.net/projects/plugins/attachment_fu/


でサムネイルを作るにはprocessorを使えるようにする必要があるんだけど、インストール時の出力に

    :processor        # Sets the image processor to use for resizing of the attached image.
                      # Options include ImageScience, Rmagick, and MiniMagick.  Default is whatever is installed.

とある通り ImageScience、Rmagick、MiniMagickが選べるけど、RMagickには何度か泣かされているので、ImageScienceを使うことにします。


で、ImageScienceのサイト( http://seattlerb.rubyforge.org/ImageScience.html )を見ると、

Requirements:
  FreeImage
  RubyInline

FreeImageとRubyInlineを入れろと書いてあります。


MacでFreeImageを入れるのは超簡単。

    sudo port selfupdate
    sudo port install freeimage

しかし仕事で使うこと考えるとWindowsでは入らないのかな?
あ、http://freeimage.sourceforge.net/requirements.html を見るとVisual .NET 2003 or 2005があれば良いらしいっす・・・
どうせLinuxにデプロイするんだからみんなMacかUbutu使えばいいのに。

次のRubyInlineはgemで。

sudo gem install RubyInline


で、最後に image_science をインストール

sudo gem install -y image_science

これでインストールするものは全部っす。

あとは画像を扱うためのモデルを生成して、いろいろごにょごにょやればオッケー。詳しく書くの疲れた。

$ ruby script/generate model FooImage foo_id:integer content_type:string filename:string thumbnail:string size:integer width:integer height:integer

CentOSにFreeImageを

http://seattlerb.rubyforge.org/ImageScience.html に書いてあるやり方の通りやってみる
まずcvsを使うので、cvsyumでインストール。

$ sudo yum install cvs

で、

$ cvs -z3 -d:pserver:anonymous@freeimage.cvs.sourceforge.net:/cvsroot/freeimage login
$ cvs -z3 -d:pserver:anonymous@freeimage.cvs.sourceforge.net:/cvsroot/freeimage co -D 2007-01-01 -P FreeImage
$ cd FreeImage
$ make
(中略)
/usr/bin/ld: ./Source/FreeImage/BitmapAccess.o: relocation R_X86_64_32S against `a local symbol' can not be used when making a shared object; recompile with -fPIC
./Source/FreeImage/BitmapAccess.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[1]: *** [libfreeimage-3.9.2.so] Error 1
make[1]: Leaving directory `/home/foo/FreeImage'
make: *** [default] Error 2

なんでー?全然意味分かんないっす。
あ、でもよく見たらこんなの書いてあった。

For 64-bit Systems:

Use 2007-02-11 instead of the date above on the cvs co. Especially if you see:

/usr/bin/ld: ./Source/FreeImage/BitmapAccess.o: relocation R_X86_64_32S against
`a local symbol' can not be used when making a shared object;
recompile with -fPIC
or:

Source/Metadata/Exif.cpp:498: error: cast from 'BYTE*' to 'DWORD' loses precision
make[1]: *** [Source/Metadata/Exif.o] Error 1

で改めてcheckoutしてみる。

$ cd ..
$ rm -rf FreeImage
$ cvs -z3 -d:pserver:anonymous@freeimage.cvs.sourceforge.net:/cvsroot/freeimage co -D 2007-02-11 -P FreeImage
$ cd FreeImage/
$ make
(中略)
cp *.a Dist
cp *.so Dist
cp Source/FreeImage.h Dist
make[1]: Leaving directory `/home/foo/FreeImage'
$

おお、うまくいったっぽい。

では次。

$ PATH=$PATH:/usr/sbin sudo make install
make -f Makefile.gnu install 
make[1]: Entering directory `/home/foo/FreeImage'
install -m 644 -o root -g root Source/FreeImage.h /usr/include
install -m 644 -o root -g root libfreeimage.a /usr/lib
install -m 755 -o root -g root libfreeimage-3.9.2.so /usr/lib
ln -sf libfreeimage-3.9.2.so /usr/lib/libfreeimage.so.3
ln -sf libfreeimage.so.3 /usr/lib/libfreeimage.so	
ldconfig
make[1]: ldconfig: Command not found
make[1]: *** [install] Error 127
make[1]: Leaving directory `/home/foo/FreeImage'
make: *** [install] Error 2

失敗しやがった。訳分からん。checkinstallも当然無理。
ちなみにldconfig は /sbin にあって、PATHに追加してやってみても同じ結果。
あ、sudoじゃなくてrootで実行したらどうでしょう?

$ su
# PATH=$PATH:/usr/sbin:/sbin:/sbin  make install
make -f Makefile.gnu install 
make[1]: Entering directory `/home/foo/FreeImage'
install -m 644 -o root -g root Source/FreeImage.h /usr/include
install -m 644 -o root -g root libfreeimage.a /usr/lib
install -m 755 -o root -g root libfreeimage-3.9.2.so /usr/lib
ln -sf libfreeimage-3.9.2.so /usr/lib/libfreeimage.so.3
ln -sf libfreeimage.so.3 /usr/lib/libfreeimage.so	
ldconfig
make[1]: Leaving directory `/home/foo/FreeImage'
#

うお、いけたよ!

もう一回、checkinstallでやってみよう

# checkinstall
(中略)
**********************************************************************

 Done. The new package has been saved to

 /usr/src/redhat/RPMS/x86_64/FreeImage-20090411-1.x86_64.rpm
 You can install it in your system anytime using: 

      rpm -i FreeImage-20090411-1.x86_64.rpm
**********************************************************************

rpmができた。

# rpm -iv /usr/src/redhat/RPMS/x86_64/FreeImage-20090411-1.x86_64.rpm
Preparing packages for installation...
FreeImage-20090411-1
#

完了っぽいっす。

あとは、RubyInlineとImageScienceをgemで入れればオッケーなはず。

$ sudo gem install RubyInline
Successfully installed ZenTest-4.0.0
Successfully installed RubyInline-3.8.1
2 gems installed
Installing ri documentation for ZenTest-4.0.0...
Installing ri documentation for RubyInline-3.8.1...
Installing RDoc documentation for ZenTest-4.0.0...
Installing RDoc documentation for RubyInline-3.8.1...
$
$ sudo gem install image_science
Successfully installed rubyforge-1.0.3
Successfully installed hoe-1.12.1
Successfully installed image_science-1.1.3
3 gems installed
Installing ri documentation for rubyforge-1.0.3...
Installing ri documentation for hoe-1.12.1...
Installing ri documentation for image_science-1.1.3...
Installing RDoc documentation for rubyforge-1.0.3...
Installing RDoc documentation for hoe-1.12.1...
Installing RDoc documentation for image_science-1.1.3...
$

これで成功のはずー!