2017 © Pedro Peláez
 

library image

This Package to deal with images crop, resize, write text, integrate with Eloquent Model to get and save inmages and creating thumbnails'

image

saad/image

This Package to deal with images crop, resize, write text, integrate with Eloquent Model to get and save inmages and creating thumbnails'

  • Tuesday, June 5, 2018
  • by ahmad-sa3d
  • Repository
  • 1 Watchers
  • 1 Stars
  • 9 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 4 Versions
  • 29 % Grown

The README.md

Image Library, used to manipulate images like crop, resize and writing texts on images

Install

You can pull in the package via composer:, (*1)

$ composer require saad/image

Register Package Service Provider for Laravel

Laravel 5.5 The package will automatically register itself., (*2)

#, (*3)

Laravel < 5.5, (*4)

add the following to your providers in config\app.php, (*5)

'providers' => [
    .....
    Saad\Image\ImageServiceProvider::class,
  ]
  

Publish package aconfiguration and assets

    php artisan vendor:publish --provider="Saad\Image\ImageServiceProvider"

use

to use Core Image Library, (*6)

    <?php

    use Saad\Image\Image;

    $image = new Image( $image_src );

    // you can then manipulate image

    // Set Save Output Format
    $image->setOutputFormat('png');

    // Set Save Options
    $image->setSaveOptions('image_name', 'Save_Path');

    // Create Thumbnail
    $image->createThumbnail(100, 100);


    // Save and destroy resource from memory
    $image->export();

    // Save and keep resource to continue manipulating same resource
    $image->export(true);

    // Get Image as data-url string
    $image->embed();

Laravel Eloquent Traits

this package ships with two traits to make it easy to save images on eloquent models, (*7)

EloquentImageSaverTrait used to dynamically save uploaded images and creating thumbnails, (*8)

EloquentPublicImageTrait used to get public url for saved images and it's created thumbnails, (*9)

Full Example, (*10)

assume we have a user Model which has image column to store user profile image, (*11)

    <?php

    ....
    use Saad\Image\Traits\EloquentImageSaverTrait;
    use Saad\Image\Traits\EloquentPublicImageTrait;

    class User extends Model
    {
        use EloquentImageSaverTrait, EloquentPublicImageTrait;

        protected static $profile_image_sizes = [
                [ 256, 256 ],   // Default image size
                [ 100, 100 ],   // Thumbnail
                [ 46, 46 ],     // Thumbnail
                [ 26, 26 ],     // Thumbnail
            ];

        /**
         * Get Image
         * @return String       Image Url
         */
        public function getImage()
        {
            return $this->getImagePublicLink( 'image', 'images/profiles/' );
        }

        /**
         * Get Image Thumbnail
         * @param  String $size Thumbnail size in format '46x46'
         * @return String       Image Thumbnail Url
         */
        public function getImageThumb( $size )
        {
            return $this->getImagePublicLink( 'image', 'images/profiles/thumb/', $size );
        }



        /**
         * Mutator To Save and Set Image
         *
         * Save Image and create thumbnails, and set image name attribute to model
         */
        public function setImageAttribute( $file )
        {
            $path = public_path( 'images/profiles/' );        

            if($file instanceof \Illuminate\Http\UploadedFile) {

                $this->attributes['image'] = $this->saveImage( $file, $path, null, static::$profile_image_sizes, function( $object, $save_name ) use($path){
                    /**
                     * Delete Old Images
                     */
                    $this->deleteOldFor( $object->image, $path );

                } );

            } else {
                $file = realpath(public_path('/images/temp/'.$file));
                $this->attributes['image'] = $this->saveLocalImage( $file, $path, null, static::$profile_image_sizes, function( $object, $save_name ) use($path){
                    /**
                     * Delete Old Images
                     */
                    $this->deleteOldFor( $object->image, $path );
                });
            }
            }
    }

The Versions

05/06 2018

dev-master

9999999-dev

This Package to deal with images crop, resize, write text, integrate with Eloquent Model to get and save inmages and creating thumbnails'

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

by Ahmed Saad

laravel image

05/06 2018

1.1.0

1.1.0.0

This Package to deal with images crop, resize, write text, integrate with Eloquent Model to get and save inmages and creating thumbnails'

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

by Ahmed Saad

laravel image

30/05 2018

1.0.2

1.0.2.0

This Package to deal with images crop, resize, write text, integrate with Eloquent Model to get and save inmages and creating thumbnails'

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

by Ahmed Saad

laravel image

02/12 2017

v1.0.1

1.0.1.0

This Package to deal with images crop, resize, write text, integrate with Eloquent Model to get and save inmages and creating thumbnails'

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

by Ahmed Saad

laravel image