protected function storeAsImage(UploadedFile $file, array $data)
    {
        // Store uploaded image, to work it.
        $this->storeAsFile($file, $data);

        // Prepare local variables.
        $properties = [];
        $disk = $this->storageDisk($data['disk']);
        $path_prefix = $data['type'].DS.$data['category'].DS;
        $path_suffix = DS.$data['name'].'.'.$data['extension'];
        $quality = setting('files.images_quality', 75);
        $is_convert = setting('files.images_is_convert', true);

        // Resave original file.
        $image = $this->imageResave(
            $this->getAbsolutePathAttribute(),
            $disk->path($path_prefix.trim($path_suffix, DS)),
            setting('files.images_max_width', 3840),
            setting('files.images_max_height', 2160),
            $quality, $is_convert
        );

        if ($image) {
            // If extension has changed, then delete original file.
            if ($data['extension'] != $image['extension']) {
                $disk->delete($this->path);
            }

            // Revision attributes.
            $this->attributes['mime_type'] = $image['mime_type'];
            $this->attributes['extension'] = $image['extension'];
            $this->attributes['filesize'] = $image['filesize'];
            $properties = [
                'width' => $image['width'],
                'height' => $image['height'],
            ];

            $path_suffix = DS.$data['name'].'.'.$image['extension'];
        }

        // Cutting images.
        foreach ($this->thumbSizes() as $key => $value) {
            @$disk->makeDirectory($path_prefix.$key);
            $image = $this->imageResave(
                $this->getAbsolutePathAttribute(),
                $disk->path($path_prefix.$key.$path_suffix),
                setting('files.images_'.$key.'_width', $value),
                setting('files.images_'.$key.'_height', $value),
                $quality, $is_convert
            );

            if (! $image) break;

            // Add to options.
            $properties += [
                $key => [
                    'width' => $image['width'],
                    'height' => $image['height'],
                    'filesize' => $image['filesize'],
                ]
            ];
        }

        return $this->setAttribute('properties', $properties);
    }
protected function storeAsImage(UploadedFile $file, array $data)
    {
        // Store uploaded image, to work it.
        $this->storeAsFile($file, $data);

        // Prepare local variables.
        $properties = [];
        $disk = $this->storageDisk($data['disk']);
        $path_prefix = $data['type'].DS.$data['category'].DS;
        $path_suffix = DS.$data['name'].'.'.$data['extension'];
        $quality = setting('files.images_quality', 75);
        $is_convert = setting('files.images_is_convert', true);

        // Resave original file.
        $image = $this->imageResave(
            $this->getAbsolutePathAttribute(),
            $disk->path($path_prefix.trim($path_suffix, DS)),
            setting('files.images_max_width', 3840),
            setting('files.images_max_height', 2160),
            $quality, $is_convert
        );

        if ($image) {
            // If extension has changed, then delete original file.
            if ($data['extension'] != $image['extension']) {
                $disk->delete($this->path);
            }

            // Revision attributes.
            $this->attributes['mime_type'] = $image['mime_type'];
            $this->attributes['extension'] = $image['extension'];
            $this->attributes['filesize'] = $image['filesize'];
            $properties = [
                'width' => $image['width'],
                'height' => $image['height'],
            ];

            $path_suffix = DS.$data['name'].'.'.$image['extension'];
        }

        // Cutting images.
        foreach ($this->thumbSizes() as $key => $value) {
            @$disk->makeDirectory($path_prefix.$key);
            $image = $this->imageResave(
                $this->getAbsolutePathAttribute(),
                $disk->path($path_prefix.$key.$path_suffix),
                setting('files.images_'.$key.'_width', $value),
                setting('files.images_'.$key.'_height', $value),
                $quality, $is_convert
            );

            if (! $image) break;

            // Add to options.
            $properties += [
                $key => [
                    'width' => $image['width'],
                    'height' => $image['height'],
                    'filesize' => $image['filesize'],
                ]
            ];
        }

        return $this->setAttribute('properties', $properties);
    }
protected function storeAsImage ( UploadedFile $ file , array $ data ) { // Store uploaded image, to work it. $ this -> storeAsFile ( $ file , $ data ) ; // Prepare local variables. $ properties = [ ] ; $ disk = $ this -> storageDisk ( $ data [ 'disk' ] ) ; $ path_prefix = $ data [ 'type' ] . DS . $ data [ 'category' ] . DS ; $ path_suffix = DS . $ data [ 'name' ] . '.' . $ data [ 'extension' ] ; $ quality = setting ( 'files.images_quality' , 75 ) ; $ is_convert = setting ( 'files.images_is_convert' , true ) ; // Resave original file. $ image = $ this -> imageResave ( $ this -> getAbsolutePathAttribute ( ) , $ disk -> path ( $ path_prefix . trim ( $ path_suffix , DS ) ) , setting ( 'files.images_max_width' , 3840 ) , setting ( 'files.images_max_height' , 2160 ) , $ quality , $ is_convert ) ; if ( $ image ) { // If extension has changed, then delete original file. if ( $ data [ 'extension' ] != $ image [ 'extension' ] ) { $ disk -> delete ( $ this -> path ) ; } // Revision attributes. $ this -> attributes [ 'mime_type' ] = $ image [ 'mime_type' ] ; $ this -> attributes [ 'extension' ] = $ image [ 'extension' ] ; $ this -> attributes [ 'filesize' ] = $ image [ 'filesize' ] ; $ properties = [ 'width' => $ image [ 'width' ] , 'height' => $ image [ 'height' ] , ] ; $ path_suffix = DS . $ data [ 'name' ] . '.' . $ image [ 'extension' ] ; } // Cutting images. foreach ( $ this -> thumbSizes ( ) as $ key => $ value ) { @ $ disk -> makeDirectory ( $ path_prefix . $ key ) ; $ image = $ this -> imageResave ( $ this -> getAbsolutePathAttribute ( ) , $ disk -> path ( $ path_prefix . $ key . $ path_suffix ) , setting ( 'files.images_' . $ key . '_width' , $ value ) , setting ( 'files.images_' . $ key . '_height' , $ value ) , $ quality , $ is_convert ) ; if ( ! $ image ) break ; // Add to options. $ properties += [ $ key => [ 'width' => $ image [ 'width' ] , 'height' => $ image [ 'height' ] , 'filesize' => $ image [ 'filesize' ] , ] ] ; } return $ this -> setAttribute ( 'properties' , $ properties ) ; }
Manipulate whith image file.

@param  Illuminate\Http\UploadedFile $file
@param  array $data
@return mixed
Manipulate whith image file .