PHPackages                             opensmarty/opensmarty-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. [Image &amp; Media](/categories/media)
4. /
5. opensmarty/opensmarty-image

ActiveLibrary[Image &amp; Media](/categories/media)

opensmarty/opensmarty-image
===========================

Opensmarty Image is a helper service to handle uploaded images and store images without duplicates.

v1.0.2(8y ago)071MITPHPPHP &gt;=5.3.0

Since Dec 4Pushed 8y ago1 watchersCompare

[ Source](https://github.com/opensmarty/opensmarty-image)[ Packagist](https://packagist.org/packages/opensmarty/opensmarty-image)[ Docs](https://github.com/opensmarty/opensmarty-image)[ RSS](/packages/opensmarty-opensmarty-image/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (4)Versions (4)Used By (1)

Opensmarty Image Service
========================

[](#opensmarty-image-service)

[![Latest Version](https://camo.githubusercontent.com/2663249a2e67750ad6f4e743fdd924c6ac626e2346f22fda871624ba5742679d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6f70656e736d617274792f6f70656e736d617274792d696d6167652e7376673f7374796c653d666c61742d737175617265)](https://github.com/opensmarty/opensmarty-image/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/ff9db85886fb4259351fb8e26aa07aa484b70dbba3791522e8632228cceadfed/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f70656e736d617274792f6f70656e736d617274792d696d6167652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/opensmarty/opensmarty-image)

Opensmarty Image is a helper service to handle uploaded images and store images without duplicates.

Build for Laravel and [Opensmarty Starter](https://opensmarty.github.io).

Install
-------

[](#install)

### Via Composer

[](#via-composer)

Install composer package to your laravel project

```
composer require opensmarty/opensmarty-image
```

Add Service Provider to `config/app.php`

```
    'providers' => [
        ...
        Opensmarty\Image\OpensmartyImageServiceProvider::class,
        ...
    ],
```

Publishing config file.

```
php artisan vendor:publish
```

After published, config file for Rest Client is `config/opensmarty-image.php`, you will need to config it to use Rest Client.

Usage
-----

[](#usage)

#### Routes

[](#routes)

```
Route::get('/image/{name}', 'ImageController@showOriginalImage');
Route::post('/image', 'ImageController@postImage');
```

#### Many Imageables

[](#many-imageables)

Use on the Model:

```
    use OpensmartyHasImageablesTrait;
```

Usage:

```
/** @var OpensmartyImage $opensmartyImage */
$opensmartyImage = OpensmartyImage::find(1);

/** @var User $user */
$user = User::find(1);

// save image relations smartly with sequence support (recommended)
$user->syncImages([1, 2], ['type' => 'cover', 'data' => json_encode('a')]);

// save image relations via save
$user->images()->save($opensmartyImage, ['type' => 'cover', 'data' => json_encode('a')]);

// save image relations via attach
$user->images()->attach(1, ['type' => 'cover', 'data' => json_encode('a')]);

// update image relations via sync
$user->images()->sync([1]);

// set as main image
$user->setAsMainImage($opensmartyImage);

// set as type main image
$user->setAsTypeMainImage('cover', $opensmartyImage);

// get all images
print_r($user->getImages()->toArray());

// get first main image
print_r($user->getMainImage()->toArray());

// get all main images
print_r($user->getMainImages()->toArray());

// get all type images
print_r($user->getTypeImages('cover')->toArray());

// get all type images and are main images
print_r($user->getTypeMainImages('cover')->toArray());
```

#### Sample Controller File

[](#sample-controller-file)

`app/Http/Controllers/ImageController.php`

```
