You are here

private function HtmlAssetInliner::convertImageToDataUri in TMGMT Translator Smartling 8

Converts images to data URIs

File

src/Context/HtmlAssetInliner.php, line 125

Class

HtmlAssetInliner

Namespace

Drupal\tmgmt_smartling\Context

Code

private function convertImageToDataUri() {
  $tags = $this
    ->getTags('//img');
  $tagsLength = $tags->length;

  # loop over all <img> tags and convert them to data uri
  for ($i = 0; $i < $tagsLength; $i++) {
    $tag = $tags
      ->item($i);
    $src = $this
      ->getFullUrl($tag
      ->getAttribute('src'));
    if ($this
      ->remote_file_exists($src)) {
      $dataUri = $this
        ->imageToDataUri($src);
      $tag
        ->setAttribute('src', $dataUri);
    }
  }

  # now save html with converted images
  $this->html = $this->dom
    ->saveHTML();
}