PHPackages                             sadovojav/yii2-image-thumbnail - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. sadovojav/yii2-image-thumbnail

ActiveYii2-extension[Image &amp; Media](/categories/media)

sadovojav/yii2-image-thumbnail
==============================

Yii2 image thumbnail component

v3.1(5y ago)2142.1k↓20.3%12[4 issues](https://github.com/sadovojav/yii2-image-thumbnail/issues)PHPPHP &gt;=5.4.0

Since Jul 5Pushed 5y ago6 watchersCompare

[ Source](https://github.com/sadovojav/yii2-image-thumbnail)[ Packagist](https://packagist.org/packages/sadovojav/yii2-image-thumbnail)[ RSS](/packages/sadovojav-yii2-image-thumbnail/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (3)Used By (0)

Yii2 image thumbnail
====================

[](#yii2-image-thumbnail)

Create image thumbnails use Imagine. Thumbnail created and cached automatically. It allows you to create placeholder with service , holder.js or Imagine

#### Features:

[](#features)

- Easy to use
- Use Imagine
- TinyPng compression
- Automaticly thumbnails caching
- Cache sorting to subdirectories
- Caching placeholder from URL (placeholdit.imgix.net)
- Use placeholdit.imgix.net

Installation
------------

[](#installation)

### Composer

[](#composer)

The preferred way to install this extension is through [Composer](http://getcomposer.org/).

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`

### Config

[](#config)

Attach the component in your config file:

```
'components' => [
    'thumbnail' => [
        'class' => 'sadovojav\image\Thumbnail',
    ],
],
```

#### Parameters

[](#parameters)

- string `basePath` = `null` - Base path
- string `prefixPath` = `null` - Prefix path
- string `cachePath` = `@runtime/thumbnails` - Cache path alias
- integer `cacheExpire` = `604800` - Cache expire time
- array `options` - Other options (placeholder/quality/additional compression)

#### Default options:

[](#default-options)

```
'options' => [
    'placeholder' => [
        'type' => sadovojav\image\Thumbnail::PLACEHOLDER_TYPE_URL,
        'backgroundColor' => '#f5f5f5',
        'textColor' => '#cdcdcd',
        'textSize' => 30,
        'text' => 'No image'
    ],
    'quality' => 92,
    'format' => null, //webp, jpg, png
    'tinyPng' => [
        'apiKey' => null
    ]
]
```

#### Note

[](#note)

`textSize - does't support on PLACEHOLDER_TYPE_URL`

#### Placeholder type

[](#placeholder-type)

- 1. sadovojav\\image\\Thumbnail::PLACEHOLDER\_TYPE\_URL - get placeholder by url
- 2. sadovojav\\image\\Thumbnail::PLACEHOLDER\_TYPE\_IMAGINE - create placeholder used Imagine

Using
-----

[](#using)

### Get cache image

[](#get-cache-image)

```
echo Yii::$app->thumbnail->img($file, $params, $options);
```

This method returns Html::img()

#### Parameters

[](#parameters-1)

- string `$file` required - Image file path
- array `$params` required - Image manipulation methods. See Methods
- array `$options` - options for Html::img()

#### For example:

[](#for-example)

```

```

### Get cache image url

[](#get-cache-image-url)

```
echo Yii::$app->thumbnail->url($file, $params);
```

This method returns cache image url

#### Parameters

[](#parameters-2)

- string `$file` required - Image file path
- array `$params` - Image manipulation methods. See Methods

#### For example:

[](#for-example-1)

```

```

### Get placeholder image

[](#get-placeholder-image)

```
echo Yii::$app->thumbnail->img($file, $params, $options);
```

This method returns Html::img()

#### Parameters

[](#parameters-3)

- string `$file` required - must to be `Null`
- array `$params` required - Image manipulation methods. See Methods
- array `$options` - options for Html::img()

#### For example:

[](#for-example-2)

```

```

### Get placeholder url

[](#get-placeholder-url)

```
echo Yii::$app->thumbnail->url($file, $params, $options);
```

This method returns path to placeholder image

#### Parameters

[](#parameters-4)

- string `$file` required - must to be `Null`
- array `$params` required - Image manipulation methods. See Methods
- array `$options` - options for Html::img()

#### For example:

[](#for-example-3)

```

```

Method
------

[](#method)

### Resize

[](#resize)

```
'resize' => [
    'width' => 320,
    'height' => 200
]
```

#### Parameters

[](#parameters-5)

- integer `width` required - New width
- integer `height` required - New height

### Crop

[](#crop)

```
'crop' => [
    'width' => 250,
    'height' => 200,
]
```

#### Parameters

[](#parameters-6)

- 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

[](#thumbnail)

```
'thumbnail' => [
    'width' => 450,
    'height' => 250,
]
```

#### Parameters

[](#parameters-7)

- integer `width` required - New width
- integer `height` required - New height
- string `mode` = `THUMBNAIL_OUTBOUND` - Thumbnail mode `THUMBNAIL_OUTBOUND` or `THUMBNAIL_INSET`

### Placeholder

[](#placeholder)

```
'placeholder' => [
    'width' => 450,
    'height' => 250,
]
```

This method return image placeholder if image file doesn't exist.

#### Parameters

[](#parameters-8)

- integer `width` required - Placeholder image width
- integer `height` required - Placeholder image height
- string `backgroundColor` = `#f5f5f5` - Background color
- string `textColor` = `#cdcdcd` - Text color
- string `text` = `No image` - Text

### Watermark

[](#watermark)

```
'watermark' => [
    'image' => IMAGE_SRC
    'posX' => 0,
    'posY' => 0,
    'width' => 50,
    'height' => 50
]
```

#### Parameters

[](#parameters-9)

- string `image` required - watermark path
- integer `posX` required - X/-X watermark position
- integer `posY` required - Y/-Y watermark position
- integer `width` - Watermark width
- integer `height` - Watermark height
- string `mode` = `THUMBNAIL_OUTBOUND` - Thumbnail mode `THUMBNAIL_OUTBOUND` or `THUMBNAIL_INSET`

### Compression (TinyPng)

[](#compression-tinypng)

```
'compress' => true
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community10

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2030 days

Total

2

Last Release

1941d ago

Major Versions

1.0.0.0 → v3.12021-01-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/0c17a869a6d802f11218035a8936a1feb52479d8695584a3a8531442d5ec81bf?d=identicon)[sadovojav](/maintainers/sadovojav)

---

Tags

thumbnailimageresizeyii2componentcropplaceholdertinypng

### Embed Badge

![Health badge](/badges/sadovojav-yii2-image-thumbnail/health.svg)

```
[![Health](https://phpackages.com/badges/sadovojav-yii2-image-thumbnail/health.svg)](https://phpackages.com/packages/sadovojav-yii2-image-thumbnail)
```

###  Alternatives

[sybio/image-workshop

Powerful PHP class using GD library to work easily with images including layer notion (like Photoshop or GIMP)

860918.1k11](/packages/sybio-image-workshop)[jbzoo/image

A PHP class that simplifies working with images

171126.9k3](/packages/jbzoo-image)[stefangabos/zebra_image

A single-file, lightweight PHP library designed for efficient image manipulation featuring methods for modifying images and applying filters

141110.4k6](/packages/stefangabos-zebra-image)[noam148/yii2-image-resize

A Yii2 component for resizing images (on the fly)

1144.6k7](/packages/noam148-yii2-image-resize)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
