PHPackages                             jmoguelruiz/yii2-resource-image - 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. jmoguelruiz/yii2-resource-image

ActiveLibrary

jmoguelruiz/yii2-resource-image
===============================

1.0.1(9y ago)211[5 issues](https://github.com/jmoguelruiz/yii2-resource-image/issues)PHP

Since Jan 21Pushed 5y ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (8)Used By (0)

### Welcome to the yii2-resource-image wiki!

[](#welcome-to-the-yii2-resource-image-wiki)

This is a component for yii2, to manage the images to upload in server and the generation of paths easiest.

Override
========

[](#override)

I think that the url path is formed for five parts: **root, base, resource, size, name**. For example:

- **root** :
- **basePath** : images/dev
- **resource** : player
- **size** : thumb
- **name** : image\_1485386176.jpg

And all togueter is [http://project-template.dev/images/dev/player/thumb/image\_1485386176.jpg](http://project-template.dev/images/dev/player/thumb/image_1485386176.jpg)

For that reason, I built this component to configure each part and generate the url most easy, I included many functions that help you to manage the images files.

Each part has its own configuration.

Root
----

[](#root)

This part is for root of url, the follow code is the default configuration:

```
[
  'isWebUrl' => true
]
```

When `isWebUrl` is true, generate `http://project-template.dev/` otherwise is `/Users/josemoguel/Documents/fuentes/project-template/frontend/web`

Basepath
--------

[](#basepath)

This part is automatically configured from environment that you are running.

```
[
 'enviroment' => $this->getEnviromentRunning()
]
```

You can set the environment if you want, there are three environments by default `dev,test,prod`.

Resource
--------

[](#resource)

The resource that belongs to the image, player, user, gamer for example.

```
[
    'type' => '',
    'isTemp' => false
]
```

When `isTemp` is `true`, add to the resource the prefix **\_temp** or if you have one configured `player_temp`, set `isTemp = true` for process the image, and later save in the real directory.

Size
----

[](#size)

You can have many sizes of the image to save.

```
[
  'type' => self::SIZE_ORIGINAL
]
```

Name
----

[](#name)

You can assign the name of image.

```
[
   'title' => '',
   'ext' => '',
   'concatTime' => true
]
```

If you put `concatTime = true` will concat the time in the name image resolving the problem with cache. `image_1485386176.jpg`.

Installation
============

[](#installation)

The way prefer is composer:

`composer install jmoguelruiz/yii2-resource-image`

Or adding in you composer file.

`"jmoguelruiz/yii2-resource-image": "1.0.*"`

In config/main inside of component put the follow code:

```
[
   'components' => [
      'resourceImage' => [
                'class' => 'common\components\ResourceImage',
                // Optional Configs
                'modelClasses' => [ // Custom models.
                    'ResourcePath' => 'common\components\ResourcePath'
                ],
                'basePaths' => [ // Base paths of your project in each enviroment.
                    'prod' => 'images/',
                    'test' => 'images/test',
                    'dev' => 'images/dev'
                ],
                'serverType' => ResourceImage::SERVER_LOCAL // Server type for now is only saved in same server.
                'prefixTemp' => 'temp', // Temp prefix for folders.
                'containerBasePath' => "@frontend/web", // Container base to save images.
                'cdn' => 'http://www.project.com', // If you want cdn.
                'symbolConcatTime' => '_' // Symbol to concat the name with the string time.
            ],
  ...
 ]
]
```

You should add the file ResourceImage in your common\\components folder, overriding this extension, for configure the follow options.

```
