protected function createCloneWithResource($resourceOrTransformation)
    {
        // No clone with no argument
        if (!$resourceOrTransformation) {
            return null;
        }

        // Handle transformation function
        if (is_callable($resourceOrTransformation)) {
            // Fail if resource not available
            $resource = $this->getImageResource();
            if (!$resource) {
                return null;
            }

            // Note: Closure may simply modify the resource rather than return a new one
            $resource = clone $resource;
            $resource = call_user_func($resourceOrTransformation, $resource) ?: $resource;

            // Clone with updated resource
            return $this->createCloneWithResource($resource);
        }

        // Ensure result is of a valid type
        if (!$resourceOrTransformation instanceof InterventionImage) {
            throw new InvalidArgumentException("Invalid resource type");
        }

        // Create clone
        $clone = clone $this;
        $clone->setImageResource($resourceOrTransformation);
        return $clone;
    }
protected function createCloneWithResource($resourceOrTransformation)
    {
        // No clone with no argument
        if (!$resourceOrTransformation) {
            return null;
        }

        // Handle transformation function
        if (is_callable($resourceOrTransformation)) {
            // Fail if resource not available
            $resource = $this->getImageResource();
            if (!$resource) {
                return null;
            }

            // Note: Closure may simply modify the resource rather than return a new one
            $resource = clone $resource;
            $resource = call_user_func($resourceOrTransformation, $resource) ?: $resource;

            // Clone with updated resource
            return $this->createCloneWithResource($resource);
        }

        // Ensure result is of a valid type
        if (!$resourceOrTransformation instanceof InterventionImage) {
            throw new InvalidArgumentException("Invalid resource type");
        }

        // Create clone
        $clone = clone $this;
        $clone->setImageResource($resourceOrTransformation);
        return $clone;
    }
protected function createCloneWithResource ( $ resourceOrTransformation ) { // No clone with no argument if ( ! $ resourceOrTransformation ) { return null ; } // Handle transformation function if ( is_callable ( $ resourceOrTransformation ) ) { // Fail if resource not available $ resource = $ this -> getImageResource ( ) ; if ( ! $ resource ) { return null ; } // Note: Closure may simply modify the resource rather than return a new one $ resource = clone $ resource ; $ resource = call_user_func ( $ resourceOrTransformation , $ resource ) ? : $ resource ; // Clone with updated resource return $ this -> createCloneWithResource ( $ resource ) ; } // Ensure result is of a valid type if ( ! $ resourceOrTransformation instanceof InterventionImage ) { throw new InvalidArgumentException ( "Invalid resource type" ) ; } // Create clone $ clone = clone $ this ; $ clone -> setImageResource ( $ resourceOrTransformation ) ; return $ clone ; }
Modify this image backend with either a provided resource, or transformation

@param InterventionImage|callable $resourceOrTransformation Either the resource to assign to the clone,
or a function which takes the current resource as a parameter
@return static
Modify this image backend with either a provided resource or transformation