2017 © Pedro Peláez
 

library opensmarty-image

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

image

opensmarty/opensmarty-image

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

  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Opensmarty Image Service

Latest Version Software License Total Downloads, (*1)

Opensmarty Image is a helper service to handle uploaded images and store images without duplicates., (*2)

Build for Laravel and Opensmarty Starter., (*3)

Install

Via Composer

Install composer package to your laravel project, (*4)

``` bash composer require opensmarty/opensmarty-image, (*5)


Add Service Provider to `config/app.php` ``` php 'providers' => [ ... Opensmarty\Image\OpensmartyImageServiceProvider::class, ... ],

Publishing config file., (*6)

``` bash php artisan vendor:publish, (*7)


After published, config file for Rest Client is `config/opensmarty-image.php`, you will need to config it to use Rest Client. ## Usage #### Routes ``` php Route::get('/image/{name}', 'ImageController@showOriginalImage'); Route::post('/image', 'ImageController@postImage');

Many Imageables

Use on the Model:, (*8)

    use OpensmartyHasImageablesTrait;

Usage:, (*9)

``` php, (*10)

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

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

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

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

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

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

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

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

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

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

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

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

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


#### Sample Controller File `app/Http/Controllers/ImageController.php` ``` php <?php namespace App\Http\Controllers; use Exception; use Illuminate\Http\Request; use Opensmarty\Image\Controllers\OpensmartyImageController; use Opensmarty\Models\Image\OpensmartyImage; use Opensmarty\Image\OpensmartyImageService; class ImageController extends Controller { public function postImage(Request $request) { $opensmartyImageService = new OpensmartyImageService(); $file = $request->file('image'); $opensmartyImage = null; try { /** @var OpensmartyImage $opensmartyImage */ $opensmartyImage = $opensmartyImageService->handleUploadedFile($file); } catch (Exception $e) { return 'Failed to save: ' . $e->getMessage(); } if (!$opensmartyImage) { return 'Failed to save uploaded image.'; } $opensmartyImageId = $opensmartyImage->getOpensmartyImageId(); return 'Saved: ' . $opensmartyImage->getImageUrl(); } public function showOriginalImage($image_name) { return OpensmartyImageController::showImage('original', $image_name); } }

Testing

bash phpunit, (*24)

Contributing

Please see CONTRIBUTING for details., (*25)

Credits

License

The MIT License (MIT). Please see License File for more information., (*26)

The Versions

07/12 2017

dev-master

9999999-dev https://github.com/opensmarty/opensmarty-image

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

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel service image starter-framework opensmarty-image opensmarty-starter

07/12 2017

v1.0.2

1.0.2.0 https://github.com/opensmarty/opensmarty-image

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

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel service image starter-framework opensmarty-image opensmarty-starter

06/12 2017

v1.0.1

1.0.1.0 https://github.com/opensmarty/opensmarty-image

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

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel service image starter-framework opensmarty-image opensmarty-starter

04/12 2017

v1.0.0

1.0.0.0 https://github.com/opensmarty/opensmarty-image

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

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel service image starter-framework opensmarty-image opensmarty-starter