Twig/ImageExtension.php
public function image64($path)
    {
        $file = new File($path, false);
        
        if (!$file->isFile() || 0 !== strpos($file->getMimeType(), 'image/')) {
            return;
        }
        
        $binary = file_get_contents($path);
        
        return sprintf('data:image/%s;base64,%s', $file->guessExtension(), base64_encode($binary));
    }
public function image64($path)
    {
        $file = new File($path, false);
        
        if (!$file->isFile() || 0 !== strpos($file->getMimeType(), 'image/')) {
            return;
        }
        
        $binary = file_get_contents($path);
        
        return sprintf('data:image/%s;base64,%s', $file->guessExtension(), base64_encode($binary));
    }
public function image64 ( $ path ) { $ file = new File ( $ path , false ) ; if ( ! $ file -> isFile ( ) || 0 !== strpos ( $ file -> getMimeType ( ) , 'image/' ) ) { return ; } $ binary = file_get_contents ( $ path ) ; return sprintf ( 'data:image/%s;base64,%s' , $ file -> guessExtension ( ) , base64_encode ( $ binary ) ) ; }
Transform image to base 64
@param  string $path relative path to image from bundle directory
@return string       base64 encoded image
Transform image to base 64