Services/AzineTwigSwiftMailer.php
private function embedImages(&$message, &$params)
    {
        // loop through the array
        foreach ($params as $key => $value) {
            // if the current value is an array
            if (is_array($value)) {
                // search for more images deeper in the arrays
                $value = $this->embedImages($message, $value);
                $params[$key] = $value;

            // if the current value is an existing file from the image-folder, embed it
            } elseif (is_string($value)) {
                if (is_file($value)) {
                    // check if the file is from an allowed folder
                    if (false !== $this->templateProvider->isFileAllowed($value)) {
                        $encodedImage = $this->cachedEmbedImage($value);
                        if (null !== $encodedImage) {
                            $id = $message->embed($encodedImage);
                            $params[$key] = $id;
                        }
                    }

                    // the $filePath isn't a regular file
                } else {
                    // add a null-value to the cache for this path, so we don't try again.
                    $this->imageCache[$value] = null;
                }

                //if the current value is a generated image
            } elseif (is_resource($value) && 0 == stripos(get_resource_type($value), 'gd')) {
                // get the image-data as string
                ob_start();
                imagepng($value);
                $imageData = ob_get_clean();

                // encode the image
                $encodedImage = new \Swift_Image($imageData, 'generatedImage'.md5($imageData));
                $id = $message->embed($encodedImage);
                $params[$key] = $id;
            }
            // don't do anything
        }

        // remove duplicate-attachments
        $message->setChildren(array_unique($message->getChildren()));

        return $params;
    }
private function embedImages(&$message, &$params)
    {
        // loop through the array
        foreach ($params as $key => $value) {
            // if the current value is an array
            if (is_array($value)) {
                // search for more images deeper in the arrays
                $value = $this->embedImages($message, $value);
                $params[$key] = $value;

            // if the current value is an existing file from the image-folder, embed it
            } elseif (is_string($value)) {
                if (is_file($value)) {
                    // check if the file is from an allowed folder
                    if (false !== $this->templateProvider->isFileAllowed($value)) {
                        $encodedImage = $this->cachedEmbedImage($value);
                        if (null !== $encodedImage) {
                            $id = $message->embed($encodedImage);
                            $params[$key] = $id;
                        }
                    }

                    // the $filePath isn't a regular file
                } else {
                    // add a null-value to the cache for this path, so we don't try again.
                    $this->imageCache[$value] = null;
                }

                //if the current value is a generated image
            } elseif (is_resource($value) && 0 == stripos(get_resource_type($value), 'gd')) {
                // get the image-data as string
                ob_start();
                imagepng($value);
                $imageData = ob_get_clean();

                // encode the image
                $encodedImage = new \Swift_Image($imageData, 'generatedImage'.md5($imageData));
                $id = $message->embed($encodedImage);
                $params[$key] = $id;
            }
            // don't do anything
        }

        // remove duplicate-attachments
        $message->setChildren(array_unique($message->getChildren()));

        return $params;
    }
private function embedImages ( & $ message , & $ params ) { // loop through the array foreach ( $ params as $ key => $ value ) { // if the current value is an array if ( is_array ( $ value ) ) { // search for more images deeper in the arrays $ value = $ this -> embedImages ( $ message , $ value ) ; $ params [ $ key ] = $ value ; // if the current value is an existing file from the image-folder, embed it } elseif ( is_string ( $ value ) ) { if ( is_file ( $ value ) ) { // check if the file is from an allowed folder if ( false !== $ this -> templateProvider -> isFileAllowed ( $ value ) ) { $ encodedImage = $ this -> cachedEmbedImage ( $ value ) ; if ( null !== $ encodedImage ) { $ id = $ message -> embed ( $ encodedImage ) ; $ params [ $ key ] = $ id ; } } // the $filePath isn't a regular file } else { // add a null-value to the cache for this path, so we don't try again. $ this -> imageCache [ $ value ] = null ; } //if the current value is a generated image } elseif ( is_resource ( $ value ) && 0 == stripos ( get_resource_type ( $ value ) , 'gd' ) ) { // get the image-data as string ob_start ( ) ; imagepng ( $ value ) ; $ imageData = ob_get_clean ( ) ; // encode the image $ encodedImage = new \ Swift_Image ( $ imageData , 'generatedImage' . md5 ( $ imageData ) ) ; $ id = $ message -> embed ( $ encodedImage ) ; $ params [ $ key ] = $ id ; } // don't do anything } // remove duplicate-attachments $ message -> setChildren ( array_unique ( $ message -> getChildren ( ) ) ) ; return $ params ; }
Recursively embed all images in the array into the message.

@param \Swift_Message $message
@param array          $params

@return array $params
Recursively embed all images in the array into the message .