public function save(array $options = [])
    {
        is_true_or_fail($this->callbacks, __d('thumber', 'No valid method called before the `{0}` method', __FUNCTION__), RuntimeException::class);

        $options = $this->getDefaultSaveOptions($options);
        $target = $options['target'];

        if (!$target) {
            $this->arguments[] = [$this->driver, $options['format'], $options['quality']];

            $target = sprintf('%s_%s.%s', md5($this->path), md5(serialize($this->arguments)), $options['format']);
        } else {
            $optionsFromTarget = $this->getDefaultSaveOptions([], $target);
            $options['format'] = $optionsFromTarget['format'];
        }

        $target = Folder::isAbsolute($target) ? $target : $this->getPath($target);
        $File = new File($target);

        //Creates the thumbnail, if this does not exist
        if (!$File->exists()) {
            $imageInstance = $this->getImageInstance();

            //Calls each callback
            foreach ($this->callbacks as $callback) {
                call_user_func($callback, $imageInstance);
            }

            $content = $imageInstance->encode($options['format'], $options['quality']);
            $imageInstance->destroy();

            is_true_or_fail($File->write($content), __d('thumber', 'Unable to create file `{0}`', rtr($target)), RuntimeException::class);
            $File->close();
        }

        //Resets arguments and callbacks
        $this->arguments = $this->callbacks = [];

        return $this->target = $target;
    }
public function save(array $options = [])
    {
        is_true_or_fail($this->callbacks, __d('thumber', 'No valid method called before the `{0}` method', __FUNCTION__), RuntimeException::class);

        $options = $this->getDefaultSaveOptions($options);
        $target = $options['target'];

        if (!$target) {
            $this->arguments[] = [$this->driver, $options['format'], $options['quality']];

            $target = sprintf('%s_%s.%s', md5($this->path), md5(serialize($this->arguments)), $options['format']);
        } else {
            $optionsFromTarget = $this->getDefaultSaveOptions([], $target);
            $options['format'] = $optionsFromTarget['format'];
        }

        $target = Folder::isAbsolute($target) ? $target : $this->getPath($target);
        $File = new File($target);

        //Creates the thumbnail, if this does not exist
        if (!$File->exists()) {
            $imageInstance = $this->getImageInstance();

            //Calls each callback
            foreach ($this->callbacks as $callback) {
                call_user_func($callback, $imageInstance);
            }

            $content = $imageInstance->encode($options['format'], $options['quality']);
            $imageInstance->destroy();

            is_true_or_fail($File->write($content), __d('thumber', 'Unable to create file `{0}`', rtr($target)), RuntimeException::class);
            $File->close();
        }

        //Resets arguments and callbacks
        $this->arguments = $this->callbacks = [];

        return $this->target = $target;
    }
public function save ( array $ options = [ ] ) { is_true_or_fail ( $ this -> callbacks , __d ( 'thumber' , 'No valid method called before the `{0}` method' , __FUNCTION__ ) , RuntimeException :: class ) ; $ options = $ this -> getDefaultSaveOptions ( $ options ) ; $ target = $ options [ 'target' ] ; if ( ! $ target ) { $ this -> arguments [ ] = [ $ this -> driver , $ options [ 'format' ] , $ options [ 'quality' ] ] ; $ target = sprintf ( '%s_%s.%s' , md5 ( $ this -> path ) , md5 ( serialize ( $ this -> arguments ) ) , $ options [ 'format' ] ) ; } else { $ optionsFromTarget = $ this -> getDefaultSaveOptions ( [ ] , $ target ) ; $ options [ 'format' ] = $ optionsFromTarget [ 'format' ] ; } $ target = Folder :: isAbsolute ( $ target ) ? $ target : $ this -> getPath ( $ target ) ; $ File = new File ( $ target ) ; //Creates the thumbnail, if this does not exist if ( ! $ File -> exists ( ) ) { $ imageInstance = $ this -> getImageInstance ( ) ; //Calls each callback foreach ( $ this -> callbacks as $ callback ) { call_user_func ( $ callback , $ imageInstance ) ; } $ content = $ imageInstance -> encode ( $ options [ 'format' ] , $ options [ 'quality' ] ) ; $ imageInstance -> destroy ( ) ; is_true_or_fail ( $ File -> write ( $ content ) , __d ( 'thumber' , 'Unable to create file `{0}`' , rtr ( $ target ) ) , RuntimeException :: class ) ; $ File -> close ( ) ; } //Resets arguments and callbacks $ this -> arguments = $ this -> callbacks = [ ] ; return $ this -> target = $ target ; }
Saves the thumbnail and returns its path
@param array $options Options for saving
@return string Thumbnail path
@see https://github.com/mirko-pagliai/cakephp-thumber/wiki/How-to-uses-the-ThumbCreator-utility#save
@throws RuntimeException
@uses getDefaultSaveOptions()
@uses getImageInstance()
@uses $arguments
@uses $callbacks
@uses $driver
@uses $path
@uses $target
Saves the thumbnail and returns its path