src/Traits/EloquentImageSaverTrait.php
public function saveLocalImage( $imageFile, $path, $name = null, Array $sizes = [], $callback = null )
    {
        $arr = explode('.',$imageFile);
        $extension = end($arr);

        if( !in_array( $extension, [ 'png', 'jpeg', 'jpg', 'gif' ] )  )
            throw new NotSupportedImageFormatException( $extension . ' extension isnot supported only supported formates are PNG, JPG, JPEG and GIF' );

        // Ok
        $image = ( new Image( $imageFile, $extension ) )->setOutputFormat( $extension, 100, PNG_NO_FILTER );
        // $image = ( new Image( $imageFile->getPathname(), $extension ) )->setOutputFormat( 'png', 100, PNG_NO_FILTER );

        $name = $name ?: str_random( 10 ) . time();

        if( empty( $sizes ) )
        {
            $save_name = $image->setSaveOptions( $name, $path )->export();
        }
        else
        {
            $main_size = array_shift( $sizes );

            $main = self::getSize( $main_size );

            $save_name = $image->createThumbnail( $main[ 'w' ], $main[ 'h' ], true )
                        ->setSaveOptions( $name, $path )->export( true );

            foreach( $sizes as $size )
            {
                $size = self::getSize( $size );
                $image->createThumbnail( $size[ 'w' ], $size[ 'h' ], true )->setSaveOptions( join( 'x', $size ) .  '_' . $save_name, $path . 'thumb'  )->export( true );
            }

            // Destroy Resource
            $image->destroy();
            
        }

        // CallBack
        if( is_callable( $callback ) )
            call_user_func( $callback, $this, $save_name, $extension );

        return $save_name;

    }
public function saveLocalImage( $imageFile, $path, $name = null, Array $sizes = [], $callback = null )
    {
        $arr = explode('.',$imageFile);
        $extension = end($arr);

        if( !in_array( $extension, [ 'png', 'jpeg', 'jpg', 'gif' ] )  )
            throw new NotSupportedImageFormatException( $extension . ' extension isnot supported only supported formates are PNG, JPG, JPEG and GIF' );

        // Ok
        $image = ( new Image( $imageFile, $extension ) )->setOutputFormat( $extension, 100, PNG_NO_FILTER );
        // $image = ( new Image( $imageFile->getPathname(), $extension ) )->setOutputFormat( 'png', 100, PNG_NO_FILTER );

        $name = $name ?: str_random( 10 ) . time();

        if( empty( $sizes ) )
        {
            $save_name = $image->setSaveOptions( $name, $path )->export();
        }
        else
        {
            $main_size = array_shift( $sizes );

            $main = self::getSize( $main_size );

            $save_name = $image->createThumbnail( $main[ 'w' ], $main[ 'h' ], true )
                        ->setSaveOptions( $name, $path )->export( true );

            foreach( $sizes as $size )
            {
                $size = self::getSize( $size );
                $image->createThumbnail( $size[ 'w' ], $size[ 'h' ], true )->setSaveOptions( join( 'x', $size ) .  '_' . $save_name, $path . 'thumb'  )->export( true );
            }

            // Destroy Resource
            $image->destroy();
            
        }

        // CallBack
        if( is_callable( $callback ) )
            call_user_func( $callback, $this, $save_name, $extension );

        return $save_name;

    }
public function saveLocalImage ( $ imageFile , $ path , $ name = null , Array $ sizes = [ ] , $ callback = null ) { $ arr = explode ( '.' , $ imageFile ) ; $ extension = end ( $ arr ) ; if ( ! in_array ( $ extension , [ 'png' , 'jpeg' , 'jpg' , 'gif' ] ) ) throw new NotSupportedImageFormatException ( $ extension . ' extension isnot supported only supported formates are PNG, JPG, JPEG and GIF' ) ; // Ok $ image = ( new Image ( $ imageFile , $ extension ) ) -> setOutputFormat ( $ extension , 100 , PNG_NO_FILTER ) ; // $image = ( new Image( $imageFile->getPathname(), $extension ) )->setOutputFormat( 'png', 100, PNG_NO_FILTER ); $ name = $ name ? : str_random ( 10 ) . time ( ) ; if ( empty ( $ sizes ) ) { $ save_name = $ image -> setSaveOptions ( $ name , $ path ) -> export ( ) ; } else { $ main_size = array_shift ( $ sizes ) ; $ main = self :: getSize ( $ main_size ) ; $ save_name = $ image -> createThumbnail ( $ main [ 'w' ] , $ main [ 'h' ] , true ) -> setSaveOptions ( $ name , $ path ) -> export ( true ) ; foreach ( $ sizes as $ size ) { $ size = self :: getSize ( $ size ) ; $ image -> createThumbnail ( $ size [ 'w' ] , $ size [ 'h' ] , true ) -> setSaveOptions ( join ( 'x' , $ size ) . '_' . $ save_name , $ path . 'thumb' ) -> export ( true ) ; } // Destroy Resource $ image -> destroy ( ) ; } // CallBack if ( is_callable ( $ callback ) ) call_user_func ( $ callback , $ this , $ save_name , $ extension ) ; return $ save_name ; }
Save Locale Images

@param  String                        $imageFile Image Path
@param  String                        $path      Path where to save Image
@param  String                        $name      Image Save Name
@param  Array|array                   $sizes     Array of image sizes
@param  Function                      $callback  Callback to run after saving image
@return String                                   Image saved name
Save Locale Images