\BEAR_Img_Adapter_Magick

iMagickクラス

Image MagicおよびGraphich MagickをサポートしたPECLのiMagickをサポートするクラスです

Example. 画像のリサイズ表示 $img = BEAR_Img::getInstance(BEAR_Img::ADAPTER_MAGICK); $img->load('http://www.bear-project.net/images/eye.jpg'); $img->resize(320,240); $img->show('jpeg');

Example. iMagickオブジェクトを直接操作

$img = BEAR_Img::getInstance(BEAR_Img::ADAPTER_MAGICK); $img->load('http://www.bear-project.net/images/eye.jpg'); $img->resize(320,240); // 木炭画エフェクト $img->adapter->charcoalImage(1, 1); $img->save(_BEAR_APP_HOME . '/tmp/picure.jpeg');

Summary

Methods
Properties
Constants
__construct()
onInject()
deleteFile()
header()
getTmpFileName()
resizeMobile()
loadRemoteFile()
getExtention()
setConfig()
getConfig()
setService()
load()
resize()
show()
save()
$image
$deleteFiles
$adapter
No constants found
getImageInfo()
_error()
_exception()
_resizeAnim()
$file
$_srcWidth
$_srcHeight
$_srcAttr
$_result
$_log
$_config
$_isAnimGif
$_animGifFile
N/A
_thisError()
$_srcType
N/A

Properties

$image

$image : resource

イメージリソース

Type

resource

$deleteFiles

$deleteFiles : array

デストラクタで消去するファイルリスト

Type

array

$adapter

$adapter : \GD

画像ライブラリオブジェクト

Type

\GD — | iMagick | Cariro

$file

$file : string

Type

string

$_srcWidth

$_srcWidth : integer

元画像の幅

Type

integer

$_srcHeight

$_srcHeight : integer

元画像の高さ

Type

integer

$_srcAttr

$_srcAttr : string

元画像の属性

Type

string

$_result

$_result : boolean

出力結果

Type

boolean

$_config

$_config : array

Class config

Type

array

$_isAnimGif

$_isAnimGif : boolean

アニメGIFではない

Type

boolean

$_animGifFile

$_animGifFile : boolean

アニメGIFファイル名

Type

boolean

$_srcType

$_srcType : string

画像のタイプ

IMAGETYPE_GIF | IMAGETYPE_JPEG | IMAGETYPE_PNG

Type

string

Methods

__construct()

__construct(array  $config) 

Constructor

設定を_configプロパティに代入します。

Parameters

array $config

ユーザー設定値

Throws

\BEAR_Img_Adapter_Magick_Exception

onInject()

onInject() : void

Inject

設定にしたがってサービスをインジェクトします。

deleteFile()

deleteFile(string  $file) : void

ファイルの消去

作業用のファイルを消去リストに追加します。

Parameters

string $file

ファイル

header()

header(null  $format = null, null  $expire = null) : void

ヘッダーを出力

イメージリソースの内容をみてHTTPヘッダーを出力します。 他の画像タイプと違い画像タイプを出力する必要がありません imagick_getmimetypeを使用

Parameters

null $format

フォーマット

null $expire

expire

getTmpFileName()

getTmpFileName(mixed  $file = false, mixed  $delete = true) : string

一時ファイル名を取得

一時画像ファイル名を生成します。 $deleteオプションがtrueの場合、デストラクタでテンポラリーファイルは消去されます

Parameters

mixed $file

ファイル名

mixed $delete

消去

Returns

string

resizeMobile()

resizeMobile() : void

モバイル端末に合わせた画像の最大リサイズ

loadRemoteFile()

loadRemoteFile(string  $file) : string

ファイルの読み込み

ローカル・リモートファイルにかかわらずファイルを読み込みます。
リモートファイルの場合はローカルにテンポラリーファイルが
作成されその名前が返されます。作られたテンポラリーファイルは
デストラクタで消去されます。キャッシュはされません。

Parameters

string $file

ファイル名

Returns

string

getExtention()

getExtention(string  $imageType) : string

image typeから拡張子を求める

Parameters

string $imageType

Returns

string

setConfig()

setConfig(mixed  $config, mixed  $values = null) : self

Set config

Parameters

mixed $config

(string) 設定キー | (array) 設定配列

mixed $values

(string) $configの時の設定値

Returns

self

getConfig()

getConfig(string  $key = null) : mixed

Get config

Parameters

string $key

設定キー、指定なければ全ての設定を取得

Returns

mixed

setService()

setService(string  $name, mixed  $service) : void

Set service

Parameters

string $name

サービスキー

mixed $service

サービス

load()

load(string  $file) : void

ファイルのロード

$fileにはローカルファイルのパスまたはリモートファイルのURLを指定します。
リモートファイルの読み込みにはphp.iniでallow_url_fopen =Onの設定が必要です。

Parameters

string $file

Throws

\BEAR_Img_Adapter_Magick_Exception

resize()

resize(integer  $width = 240, integer  $height = 240, integer  $filter = \Imagick::FILTER_LANCZOS, integer  $blur = 1, boolean  $fit = true) : void

画像のリサイズ

画像をリサイズします。アニメーションGIFもリサイズできます。
リサイズ時に$filterを指定することもできます。
$filterはIMAGICK_FILTER_*形式で指定します。

Parameters

integer $width
integer $height
integer $filter
integer $blur
boolean $fit

show()

show(string  $format) : void

画像を指定のフォーマットで表示

画像を表示します。

Parameters

string $format

画像フォーマット

save()

save(string  $filePath, mixed  $format = false) 

画像保存

指定のパスに画像を保存します。

Parameters

string $filePath

保存画像のファイルパス

mixed $format

フォーマット

getImageInfo()

getImageInfo() : void

画像情報の取得

getimagesizeで得られる画像情報を以下のプロパティに格納します。

_srcWidth int
srcHeight int
srcType   int
srcAttr   string

_error()

_error(string  $errorFunc) : void

エラー終了

Parameters

string $errorFunc

ファンクション名

_exception()

_exception(string  $msg, array  $config = array()) : \BEAR_Exception

例外の作成

Parameters

string $msg

例外メッセージ

array $config

例外config

Returns

\BEAR_Exception

_resizeAnim()

_resizeAnim(integer  $width = 240) : void

アニメーションGIFのリサイズ

アニメーションGIFをリサイズします。magic関数には用意されていない機能なので
シェルでconvertコマンドを実行しています

Parameters

integer $width

画像の幅

_thisError()

_thisError(string  $func, string  $msg = null) : void

エラー終了

エラー終了します。

Parameters

string $func

コール元のメソッド名

string $msg

エラーメッセージ

Throws

\BEAR_Img_Adapter_Magick_Exception