Create image thumbnails use Imagine. Thumbnail created and cached automatically. It allows you to create placeholder with service http://placehold.it/ or holder.js.
- Easy to use
- Use Imagine
- Automaticly thumbnails caching
- Cache sorting to subdirectories
- Use placehold.it & holder.js
The preferred way to install this extension is through Composer.
Either run php composer.phar require sadovojav/yii2-image-thumbnail "dev-master"
or add "sadovojav/yii2-image-thumbnail": "dev-master"
to the require section of your composer.json
Attach the component in your config file:
'bootstrap' => [
'thumbnail',
],
'components'=>[
'thumbnail' => [
'class' => 'sadovojav\image\Thumbnail',
],
],
- string
basePath
=@runtime
- Base path - string
cachePath
=@runtime/thumbnails
- Cache path alias - integer
cacheExpire
=604800
- Cache expire time - array
options
- other options (placeholder)
'options' => [
'placeholder' => [
'type' => sadovojav\image\Thumbnail::PLACEHOLDER_TYPE_URL,
'backgroundColor' => '#f5f5f5',
'textColor' => '#cdcdcd',
'text' => 'Ooops!'
],
'quality => 92
]
Placeholder type
- sadovojav\image\Thumbnail::PLACEHOLDER_TYPE_JS - holder.js
- sadovojav\image\Thumbnail::PLACEHOLDER_TYPE_URL - get placeholder by url
echo Yii::$app->thumbnail->img($file, $params, $options);
This method returns Html::img()
- string
$file
required - Image file path - array
$params
- Image manipulation methods. See Methods - array
$options
- options for Html::img()
echo Yii::$app->thumbnail->url($file, $params);
This method returns cache image url
- string
$file
required - Image file path - array
$params
- Image manipulation methods. See Methods
'resize' => [
'width' => 320,
'height' => 200
]
- integer
width
required - New width - integer
height
required - New height
'crop' => [
'width' => 250,
'height' => 200,
]
- integer
width
required - New width - integer
height
required - New height - integer
x
=0
- X start crop position - integer
y
=0
- Y start crop position
'thumbnail' => [
'width' => 450,
'height' => 250,
]
- integer
width
required - New width - integer
height
required - New height - string
mode
=THUMBNAIL_OUTBOUND
- Thumbnail modeTHUMBNAIL_OUTBOUND
orTHUMBNAIL_INSET
'placeholder' => [
'width' => 450,
'height' => 250,
]
This method return image placeholder if image file doesn't exist.
- integer
width
required - Placeholder image width - integer
height
required - Placeholder image height - string
backgroundColor
=#f5f5f5
- Background color - string
textColor
=#cdcdcd
- Text color - string
text
=Ooops!
- Text