Skip to content

Commit

Permalink
git-svn-id: http://smalllight.googlecode.com/svn/trunk@2 31ed2c5f-a43…
Browse files Browse the repository at this point in the history
…9-ea96-03ff-1d9a14941ac2
  • Loading branch information
yamac.ld@gmail.com committed Oct 4, 2010
1 parent 51bc1c6 commit 37b9ae6
Show file tree
Hide file tree
Showing 12 changed files with 6,029 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Makefile.in
@@ -0,0 +1,37 @@
APXS=@APXS@
PACKAGE=@PACKAGE_NAME@
VERSION=@PACKAGE_VERSION@
PACKAGEDIR=$(PACKAGE)-$(VERSION)
PACKAGETGZ=$(PACKAGE)-$(VERSION).tar.gz

ifneq ("@IMLIB2_CONFIG@","")
IMLIB2_INCLUDES=`@IMLIB2_CONFIG@ --cppflags`
IMLIB2_LIBS=`@IMLIB2_CONFIG@ --libs`
endif
ifneq ("@WAND_CONFIG@","")
WAND_INCLUDES=`@WAND_CONFIG@ --cppflags`
WAND_LIBS=`@WAND_CONFIG@ --libs`
endif
CFLAGS=@CFLAGS_IMLIB2@ @CFLAGS_WAND@

all:
$(APXS) -c "$(CFLAGS) $(IMLIB2_INCLUDES) $(IMLIB2_LIBS) $(WAND_INCLUDES) $(WAND_LIBS)" \
mod_small_light.c mod_small_light_*.c

install:
$(APXS) -ia mod_small_light.la

clean:
rm -rf *.o *.a *.so *.lo *.la *.slo a.out .libs .deps

distclean: clean
rm -rf Makefile config.cache config.log config.status autom4te.cache $(PACKAGETGZ) $(PACKAGEDIR)

dist:
mkdir $(PACKAGEDIR)
autoconf
cp mod_small_light.c mod_small_light.h mod_small_light_*.c mod_small_light_*.h $(PACKAGEDIR)
cp configure configure.in Makefile.in README README.* $(PACKAGEDIR)
tar cvzf $(PACKAGETGZ) $(PACKAGEDIR)
rm -rf $(PACKAGEDIR)

139 changes: 139 additions & 0 deletions README
@@ -0,0 +1,139 @@
mod_small_light - Dynamic image transformation module for Apache2
==============================================================================

The mod_small_light provides a dynamic image transformation.


Build
-----

Simply run the configure script for analyzing your environment automatically.

./configure

Or you can specify the location of each imlib2-config, Wand-config and apxs
by using --with options.
(currentry '--with-apxs' is required)

./configure --with-imlib2-config=/usr/local/imlib2/bin/imlib2-config
./configure --with-Wand-config=/usr/local/ImageMagick/bin/Wand-config
./configure --with-apxs=/usr/local/apache2/bin/apxs

Or if you don't have a plan to use imlib2 or Wand, you can specify --without
options.

./configure --without-imlib2
./configure --without-Wand

And then, make and make install to complete installation.

make
sudo make install


Usage
-----

This module is implemented as an output filter. Use SetOutputFilter directive
to activate it.


* for local use.

RewriteRule ^/images/(.+)$ /your/local/images/$1 [L]
RewriteRule ^/resize/(.+)$ /small_light(dw=400,dh=400,ds=s)/$1 [P,L]
RewriteRule ^/small_light[^/]*/(.+)$ /your/local/images/$1
<LocationMatch ^/small_light[^/]*/>
SetOutputFilter SMALL_LIGHT
</LocationMatch>

* for dedicated use.

RewriteRule ^/images/(.+)$ http://img.example.com/your/images/$1 [P,L]
RewriteRule ^/resize/(.+)$ /small_light(dw=400,dh=400,ds=s)/$1 [P,L]
RewriteRule ^/small_light[^/]*/(.+)$ http://img.example.com/your/images/$1 [P,L]
<LocationMatch ^/small_light[^/]*/>
SetOutputFilter SMALL_LIGHT
</LocationMatch>


After you set the output filter, your apache transforms an image by
transformation pattern specified in the URI.


Pattern string
--------------

The pattern string specifies as KEY=VALUE format in small_light().

KEY VALUE [TYPE OF VALUE]
-------------------------------------------------------------------
sx source x [coord]
sy source y [coord]
sw source width [coord]
sh source height [coord]
dx destination x [coord]
dy destination y [coord]
dw destination width [coord]
dh destination height [coord]
da destination aspect ratio control [char]
(s=short-edge l=long-edge n=nope default:l)
ds destination scaling control [char]
(s=force scale n=no scale small image default:n)
cw canvas width [number]
ch canvas height [number]
cc canvas color(default:000000) [color]
bw border width [number]
bh border height [number]
bc border color(default:000000) [color]
pt pass through control [char]
(ptss:pass through when size of src-image < dest
ptls:pass through when size of src-image > dest
n:none default:n)
q quality(affects only jpeg or png, 0-100) [number]
of output format(jpeg,png,tiff,gif) [char] *1
inhexif inherit EXIF [char] *2
(n:none y:inherit default:n)
info add transformation description to HTTP Header [number]
(0:none 1:add 初期値:0)
p pattern name(see below)
e engine name(imlib2,imagemagick,dummy) [char]
sharpen e=imlib2,sharpen=radius
e=imagemagick,sharpen=radius,sigma
unsharp e=imagemagick,unsharp=radius,sigma,amount,threshold
blur e=imlib2,blur=radius
e=imagemagick,blur=radius,sigma
-------------------------------------------------------------------
*1 of=gif is supported only when e=imagemagick
*2 inhexif is supported only when e=imlib2

TYPE OF VALUE
-------------------------------------------------------------------
coord corrdinate. pixel, or percent by appending 'p'.
char character
number number
color rrggbb or rrggbbaa. ffffff as white, 000000 as black.
-------------------------------------------------------------------

* Pattern name

You can use named pattern by using SmallLightPatternDefine directive. This
will reduce length and complexity of your URI.

SmallLightPatternDefine <PATTERN_NAME> <PATTERN STRING>

Some examples here.

SmallLightPatternDefine THUMB_SMALL sx=5p,sy=5p,sw=90p,sh=90p,dw=40,dh=40,da=l,cw=40,ch=40,cc=ffffff,q=80,of=jpeg
SmallLightPatternDefine THUMB_MEDIUM sx=5p,sy=5p,sw=90p,sh=90p,dw=96,dh=96,da=l,cw=96,ch=96,cc=ffffff,q=80,of=jpeg
SmallLightPatternDefine THUMB_LARGE sx=5p,sy=5p,sw=90p,sh=90p,dw=200,dh=200,da=l,cw=200,ch=200,cc=ffffff,q=80,of=jpeg

To use named pattern, simply small_light(p=PATTERN_NAME). The pattern could
be overridden by patterns followed.

small_light(p=THUMB_SMALL)

OR

small_light(p=THUMB_SMALL,q=80) * 'q' will be overridden to 80.

140 changes: 140 additions & 0 deletions README.JA
@@ -0,0 +1,140 @@
mod_small_light - Dynamic image transformation module for Apache2
==============================================================================

mod_small_lightを用いることでダイナミックな画像変換が可能です。


ビルド
------

引数なしで configure スクリプトを実行して環境を自動認識します。

./configure

または --with オプションで imlib2-config, Wand-config や apxs の場所を指定し
ます。
(現在 --with-apxs は必須です)

./configure --with-imlib2-config=/usr/local/imlib2/bin/imlib2-config
./configure --with-Wand-config=/usr/local/ImageMagick/bin/Wand-config
./configure --with-apxs=/usr/local/apache2/bin/apxs

またはもし imlib2 か Wand を使用しないのであれば、--without オプションを指定
します。

./configure --without-imlib2
./configure --without-Wand

次に make と make install を実施してインストールを完了します。

make
sudo make install



使い方
------

このモジュールは Apache のアウトプットフィルターとして実装されています。
有効にするためには SetOutputFilter ディレクティブを使用します。


* 通常使用の例

RewriteRule ^/images/(.+)$ /your/local/images/$1 [L]
RewriteRule ^/resize/(.+)$ /small_light(dw=400,dh=400,ds=s)/$1 [P,L]
RewriteRule ^/small_light[^/]*/(.+)$ /your/local/images/$1
<LocationMatch ^/small_light[^/]*/>
SetOutputFilter SMALL_LIGHT
</LocationMatch>

* 画像変換専用サーバー用の例

RewriteRule ^/images/(.+)$ http://img.example.com/your/images/$1 [P,L]
RewriteRule ^/resize/(.+)$ /small_light(dw=400,dh=400,ds=s)/$1 [P,L]
RewriteRule ^/small_light[^/]*/(.+)$ http://img.example.com/your/images/$1 [P,L]
<LocationMatch ^/small_light[^/]*/>
SetOutputFilter SMALL_LIGHT
</LocationMatch>


アウトプットフィルターの定義を済ませれば、ApacheはURI中に定義された画像変換パ
ターンを用いて画像を変換するようになります。


Pattern文字列
-------------

パターン文字列は キー=値 の形式でURI中の small_light() 内に記述します。

キー 値 [値の種別]
-------------------------------------------------------------------
sx 変換前画像x座標 [coord]
sy 変換前画像y座標 [coord]
sw 変換前画像横幅 [coord]
sh 変換前画像縦幅 [coord]
dx 変換後画像x座標 [coord]
dy 変換後画像y座標 [coord]
dw 変換後画像横幅 [coord]
dh 変換後画像縦幅 [coord]
da 変換後画像アスペクト比制御種別 [char]
(s=短辺基準 l=長辺基準 n=なし 初期値:l)
ds 変換後画像スケーリング制御種別 [char]
(s=小さい画像も拡大 n=小さい画像はそのまま 初期値:n)
cw キャンバス横幅 [number]
ch キャンバス縦幅 [number]
cc キャンバス色(初期値:000000) [color]
bw ボーダー横幅 [number]
bh ボーダー縦幅 [number]
bc ボーダー色(初期値:000000) [color]
pt 処理種別 [char]
(ptss:変換後画像より変換前画像が小さい場合にパススルー
ptls:変換後画像より変換前画像が大きい場合にパススルー
n:なし 初期値:n)
q クォリティー(jpegかpngのときのみ影響, 0~100) [number]
of 出力形式(jpeg,png,tiff,gif) [char] *1
inhexif 変換前画像のEXIF情報を変換後画像に引き継ぐ [char] *2
(n:引き継がない y:引き継ぐ 初期値:n)
info 詳細情報をHTTP Headerに出力 [number]
(0:しない 1:する 初期値:0)
p パターン名(後述)
e 画像変換エンジン名(imlib2,imagemagick,gegl,dummy) [char]
sharpen e=imlib2,sharpen=radius
e=imagemagick,sharpen=radius,sigma
unsharp e=imagemagick,unsharp=radius,sigma,amount,threshold
blur e=imlib2,blur=radius
e=imagemagick,blur=radius,sigma
-------------------------------------------------------------------
*1 of=gifはe=imagemagickのみ対応
*2 inhexifはe=imlib2のみ対応

値の種類
-------------------------------------------------------------------
coord 座標。単純にピクセル指定かまたはpを付けることで%指定。
char 文字列
number 数値
color rrggbb形式またはrrggbbaa形式。ffffffで白、000000で黒。
-------------------------------------------------------------------

* パターン名

よく利用するパターン文字列を SmallLightPatternDefine ディレクティブで
パターン名を定義しておくことができます。これによりURIが単純で短くなります。

SmallLightPatternDefine <パターン名> <パターン文字列>

使用例:

SmallLightPatternDefine THUMB_SMALL sx=5p,sy=5p,sw=90p,sh=90p,dw=40,dh=40,da=l,cw=40,ch=40,cc=ffffff,q=80,of=jpeg
SmallLightPatternDefine THUMB_MEDIUM sx=5p,sy=5p,sw=90p,sh=90p,dw=96,dh=96,da=l,cw=96,ch=96,cc=ffffff,q=80,of=jpeg
SmallLightPatternDefine THUMB_LARGE sx=5p,sy=5p,sw=90p,sh=90p,dw=200,dh=200,da=l,cw=200,ch=200,cc=ffffff,q=80,of=jpeg

パターン名を使うには単純に small_light(p=パターン名) とします。パターンはパタ
ーン名に続くパターン文字列で上書きできます。

small_light(p=THUMB_SMALL)

OR

small_light(p=THUMB_SMALL,q=80) * qは80に上書きされます

0 comments on commit 37b9ae6

Please sign in to comment.