Twig/Extension/ImExtension.php
public function convert($html)
    {
        preg_match_all('|<img ([^>]+)>|', $html, $matches);

        foreach($matches[0] as $img)
        {
            $crawler = new Crawler();
            $crawler->addContent($img);
            $imgTag = $crawler->filter("img");

            $src = $imgTag->attr('src');
            $width = $imgTag->attr('width');
            $height = $imgTag->attr('height');

            if (!empty($width) || !empty($height)) {
                $format = $width . "x" . $height;
                $updatedTagString = preg_replace("| src=[\"']" . $src . "[\"']|", " src=\"" . $this->imResize($src, $format) . "\"", $img);
                $html = str_replace($img, $updatedTagString, $html);
            }
        }

        return $html;
    }
public function convert($html)
    {
        preg_match_all('|<img ([^>]+)>|', $html, $matches);

        foreach($matches[0] as $img)
        {
            $crawler = new Crawler();
            $crawler->addContent($img);
            $imgTag = $crawler->filter("img");

            $src = $imgTag->attr('src');
            $width = $imgTag->attr('width');
            $height = $imgTag->attr('height');

            if (!empty($width) || !empty($height)) {
                $format = $width . "x" . $height;
                $updatedTagString = preg_replace("| src=[\"']" . $src . "[\"']|", " src=\"" . $this->imResize($src, $format) . "\"", $img);
                $html = str_replace($img, $updatedTagString, $html);
            }
        }

        return $html;
    }
public function convert ( $ html ) { preg_match_all ( '|<img ([^>]+)>|' , $ html , $ matches ) ; foreach ( $ matches [ 0 ] as $ img ) { $ crawler = new Crawler ( ) ; $ crawler -> addContent ( $ img ) ; $ imgTag = $ crawler -> filter ( "img" ) ; $ src = $ imgTag -> attr ( 'src' ) ; $ width = $ imgTag -> attr ( 'width' ) ; $ height = $ imgTag -> attr ( 'height' ) ; if ( ! empty ( $ width ) || ! empty ( $ height ) ) { $ format = $ width . "x" . $ height ; $ updatedTagString = preg_replace ( "| src=[\"']" . $ src . "[\"']|" , " src=\"" . $ this -> imResize ( $ src , $ format ) . "\"" , $ img ) ; $ html = str_replace ( $ img , $ updatedTagString , $ html ) ; } } return $ html ; }
Called by the compile method to replace the image sources with image cache sources

@param string $html

@return string
Called by the compile method to replace the image sources with image cache sources