Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
CostaRico committed Aug 9, 2014
1 parent a908be4 commit 3dc07e8
Showing 1 changed file with 49 additions and 36 deletions.
85 changes: 49 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,50 @@ if($image){

```

Details
-------------
1. Get images
```php
$model->getImage(); //returns main image for model (first added image or setted as main)

$model->removeImages(); //returns array with images

//If there is no images for model, above methods will return PlaceHolder images or null
//If you want placeholder set up it in module configuration (see documentation)

```
2. Remove image/images
```php
$model->removeImage($image); //you must to pass image (object)

$model->removeImages(); //will remove all images of this model
```

3. Set main image
```php
$model->attachImage($absolutePathToImage, true); //will attach image and make it main

foreach($model->getImages() as $img){
if($img->id == $ourId){
$model->setMainImage($img);//will set current image main
}
}
```

4. Get image sizes
```php
$image = $model->getImage();
$sizes = $image->getSizesWhen('x500');
echo '<img width="'.$sizes['width'].'" height="'.$sizes['height'].'" src="'.$image->getUrl('x500').'" />';
```

5. Get original image
```php
$img = $model->getImage();
echo $img->getPathToOrigin();
```


Installation
-------------
1. Add Yii2-user to the require section of your composer.json file:
Expand All @@ -70,7 +114,7 @@ Installation
</pre>

4. setup module
<pre>
```php
'modules' => [
'yii2images' => [
'class' => 'rico\yii2images\Module',
Expand All @@ -79,12 +123,13 @@ Installation
'imagesStorePath' => 'images/store', //path to origin images
'imagesCachePath' => 'images/cache', //path to resized copies
'graphicsLibrary' => 'GD' //but really its better to use 'Imagick'
'placeHolderPath' => '@webroot/images/placeHolder.png' // if you want to get placeholder when image not exists, string will be processed by Yii::getAlias
],
],
</pre>
```

5. attach behaviour to your model (be sure that your model has "id" property)
<pre>
```php
public function behaviors()
{
return [
Expand All @@ -93,40 +138,8 @@ Installation
]
];
}
</pre>
```

Thats all!

Details
-------------

1. Remove image/images
<pre>
$model->removeImage($image); //you must to pass image (object)

$model->removeImages(); //will remove all images of this model
</pre>

2. Set main image
<pre>
$model->attachImage($absolutePathToImage, true); //will attach image and make it main

foreach($model->getImages() as $img){
if($img->id == $ourId){
$model->setMainImage($img);//will set current image main
}
}
</pre>

3. Get image sizes
<pre>
$image = $model->getImage();
$sizes = $image->getSizesWhen('x500');
echo '&lt;img width="'.$sizes['width'].'" height="'.$sizes['height'].'" src="'.$image->getUrl('x500').'" />';
</pre>

4. Get original image
<pre>
$img = $model->getImage();
echo $img->getPathToOrigin();
</pre>

0 comments on commit 3dc07e8

Please sign in to comment.