検索条件
全2件
(1/1ページ)
Webアプリ開発中に ImageMagick(perlmagick)が SpeedyCGI 環境でまともに動かない不具合に当たりました。
この問題は FastCGI や mod_perl2 では起きません。
スクリプト
#!/usr/bin/speedy use Image::Magick(); print "Content-Type: text/plain\n\n"; print "Image::Magick Version $Image::Magick::VERSION \n"; my $image = Image::Magick->new; $image->Read( 'x.png' );
実行結果。
~$ test.pl Image::Magick Version 6.3.7 ~$ test.pl Segmentation fault
~$ test.pl Image::Magick Version 6.5.9 ~$ test.pl Segmentation fault
不明。
#!/usr/bin/speedy delete $INC{'Image/Magick.pm'}; require Image::Magick; print "Content-Type: text/plain\n\n"; print "Image::Magick Version $Image::Magick::VERSION \n"; my $image = Image::Magick->new; $image->Read( 'x.png' );
requireで毎回確実にロードさせる細工をすることで問題は起こらなくなりました。Image::Magickモジュールがキャッシュされませんが、evalを飛び越えてSpeedyCGIごと落ちるよりはマシということで……。
gccの(ライブラリlibgomp )バグのようです。gcc 4.3より前のVersion(4.2以下)で、amd64環境の時起こる模様。
gcc 4.4でも起きたので関係ないようです。4年経っても解決されてないとは思わなかった(汗)
256色png(8bitカラーパレット)で保存する方法。
$image->Read( 'x.png' ); $image->Resize(width=>133, height=>100); $image->Quantize(colorspace=>'RGB',colors=>256); $image->Set(depth => 8); $image->Write( 'y.png' );
HTMLのソース。余計な改行やスペースを入れないこと。
<div class="image"><span class="dummy"></span><img src="xxx.png" /></div>
CSS。
div.image { border: 1px solid #8ff; min-width: 320px; width: 320px; height: 240px; _width: 322px; _height: 242px; text-align: center; display: block; } div.image span.dummy { height: 240px; width: 0px; vertical-align: middle; display: inline-block; } div.image img { max-width: 320px; max-height: 240px; vertical-align: middle; /* IE6 hack */ _margin-top: -1px; /* IE6 でアスペクト比保存縮小のためのhack */ _width: expression(this.height>240 && this.width*3<this.height*4 ? Math.floor(this.width*240/this.height) : (this.width > 320 ? 320: true )); _height: expression(this.height>240 ? 240: true ); } *:first-child+html div.image img { /* IE7 hack */ margin-top: -1px; }
「span.dummy」を「display: inline-block」するのが縦方向センタリングのポイントです。
img { max-width: 320px; max-height: 240px; _width: expression(this.height>240 && this.width*3<this.height*4 ? Math.floor(this.width*240/this.height) : (this.width > 320 ? 320: true )); _height: expression(this.height>240 ? 240: true ); }
240と320を好みのサイズに変更してください。