public function manipulateImage($variant, $callback)
    {
        return $this->manipulate(
            $variant,
            function (AssetStore $store, $filename, $hash, $variant) use ($callback) {
                /** @var Image_Backend $backend */
                $backend = $this->getImageBackend();

                // If backend isn't available
                if (!$backend || !$backend->getImageResource()) {
                    return null;
                }

                // Delegate to user manipulation
                $result = $callback($backend);

                // Empty result means no image generated
                if (!$result) {
                    return null;
                }

                // Write from another container
                if ($result instanceof AssetContainer) {
                    try {
                        $tuple = $store->setFromStream($result->getStream(), $filename, $hash, $variant);
                        return [$tuple, $result];
                    } finally {
                        gc_collect_cycles();
                    }
                }

                // Write from modified backend
                if ($result instanceof Image_Backend) {
                    try {
                        /** @var Image_Backend $result */
                        $tuple = $result->writeToStore(
                            $store,
                            $filename,
                            $hash,
                            $variant,
                            array('conflict' => AssetStore::CONFLICT_USE_EXISTING)
                        );

                        return [$tuple, $result];
                    } finally {
                        gc_collect_cycles();
                    }
                }

                // Unknown result from callback
                throw new LogicException("Invalid manipulation result");
            }
        );
    }
public function manipulateImage($variant, $callback)
    {
        return $this->manipulate(
            $variant,
            function (AssetStore $store, $filename, $hash, $variant) use ($callback) {
                /** @var Image_Backend $backend */
                $backend = $this->getImageBackend();

                // If backend isn't available
                if (!$backend || !$backend->getImageResource()) {
                    return null;
                }

                // Delegate to user manipulation
                $result = $callback($backend);

                // Empty result means no image generated
                if (!$result) {
                    return null;
                }

                // Write from another container
                if ($result instanceof AssetContainer) {
                    try {
                        $tuple = $store->setFromStream($result->getStream(), $filename, $hash, $variant);
                        return [$tuple, $result];
                    } finally {
                        gc_collect_cycles();
                    }
                }

                // Write from modified backend
                if ($result instanceof Image_Backend) {
                    try {
                        /** @var Image_Backend $result */
                        $tuple = $result->writeToStore(
                            $store,
                            $filename,
                            $hash,
                            $variant,
                            array('conflict' => AssetStore::CONFLICT_USE_EXISTING)
                        );

                        return [$tuple, $result];
                    } finally {
                        gc_collect_cycles();
                    }
                }

                // Unknown result from callback
                throw new LogicException("Invalid manipulation result");
            }
        );
    }
public function manipulateImage ( $ variant , $ callback ) { return $ this -> manipulate ( $ variant , function ( AssetStore $ store , $ filename , $ hash , $ variant ) use ( $ callback ) { /** @var Image_Backend $backend */ $ backend = $ this -> getImageBackend ( ) ; // If backend isn't available if ( ! $ backend || ! $ backend -> getImageResource ( ) ) { return null ; } // Delegate to user manipulation $ result = $ callback ( $ backend ) ; // Empty result means no image generated if ( ! $ result ) { return null ; } // Write from another container if ( $ result instanceof AssetContainer ) { try { $ tuple = $ store -> setFromStream ( $ result -> getStream ( ) , $ filename , $ hash , $ variant ) ; return [ $ tuple , $ result ] ; } finally { gc_collect_cycles ( ) ; } } // Write from modified backend if ( $ result instanceof Image_Backend ) { try { /** @var Image_Backend $result */ $ tuple = $ result -> writeToStore ( $ store , $ filename , $ hash , $ variant , array ( 'conflict' => AssetStore :: CONFLICT_USE_EXISTING ) ) ; return [ $ tuple , $ result ] ; } finally { gc_collect_cycles ( ) ; } } // Unknown result from callback throw new LogicException ( "Invalid manipulation result" ) ; } ) ; }
Wrapper for manipulate that passes in and stores Image_Backend objects instead of tuples

@param string $variant
@param callable $callback Callback which takes an Image_Backend object, and returns an Image_Backend result.
If this callback returns `true` then the current image will be duplicated without modification.
@return DBFile The manipulated file
Wrapper for manipulate that passes in and stores Image_Backend objects instead of tuples