src/Sulu/Bundle/MediaBundle/Media/ImageConverter/ImagineImageConverter.php
private function modifyAllLayers(ImageInterface $image, callable $modifier)
    {
        if (count($image->layers())) {
            $countLayer = 0;
            $image->layers()->coalesce();

            /** @var ImageInterface $temporaryImage */
            $temporaryImage = null;
            foreach ($image->layers() as $layer) {
                ++$countLayer;
                $layer = call_user_func($modifier, $layer);
                if (1 === $countLayer) {
                    $temporaryImage = $layer; // use first layer as main image
                } else {
                    $temporaryImage->layers()->add($layer);
                }
            }
            $image = $temporaryImage;
        } else {
            $image = call_user_func($modifier, $image);
        }

        return $image;
    }
private function modifyAllLayers(ImageInterface $image, callable $modifier)
    {
        if (count($image->layers())) {
            $countLayer = 0;
            $image->layers()->coalesce();

            /** @var ImageInterface $temporaryImage */
            $temporaryImage = null;
            foreach ($image->layers() as $layer) {
                ++$countLayer;
                $layer = call_user_func($modifier, $layer);
                if (1 === $countLayer) {
                    $temporaryImage = $layer; // use first layer as main image
                } else {
                    $temporaryImage->layers()->add($layer);
                }
            }
            $image = $temporaryImage;
        } else {
            $image = call_user_func($modifier, $image);
        }

        return $image;
    }
private function modifyAllLayers ( ImageInterface $ image , callable $ modifier ) { if ( count ( $ image -> layers ( ) ) ) { $ countLayer = 0 ; $ image -> layers ( ) -> coalesce ( ) ; /** @var ImageInterface $temporaryImage */ $ temporaryImage = null ; foreach ( $ image -> layers ( ) as $ layer ) { ++ $ countLayer ; $ layer = call_user_func ( $ modifier , $ layer ) ; if ( 1 === $ countLayer ) { $ temporaryImage = $ layer ; // use first layer as main image } else { $ temporaryImage -> layers ( ) -> add ( $ layer ) ; } } $ image = $ temporaryImage ; } else { $ image = call_user_func ( $ modifier , $ image ) ; } return $ image ; }
Applies a callback to every layer of an image and returns the resulting image.

@param ImageInterface $image
@param callable $modifier The callable to apply to all layers

@return ImageInterface
Applies a callback to every layer of an image and returns the resulting image .