You are here

function _css_emimage_replace in CSS Embedded Images 6

Same name and namespace in other branches
  1. 6.2 css_emimage.module \_css_emimage_replace()
  2. 7 css_emimage.inc \_css_emimage_replace()

preg_replace_callback() callback to replace URLs with data URIs.

1 string reference to '_css_emimage_replace'
_css_emimage_process in ./css_emimage.module
Helper function to replace URLs with data URIs.

File

./css_emimage.module, line 102

Code

function _css_emimage_replace($matches) {
  $replacement = $matches[0];
  if ($image = image_get_info($matches[2])) {
    $ielimit = variable_get('css_emimage_ielimit', 1);

    // only embed images less than 32KB, thanks IE
    if (!$ielimit || $ielimit && $image['file_size'] * 1.3333 < 32768) {
      $replacement = str_replace($matches[1], 'url(data:' . $image['mime_type'] . ';base64,' . base64_encode(file_get_contents($matches[2])) . ')', $replacement);

      // Overrides for IE6 and IE7
      $replacement .= "\n * html " . $matches[0] . "\n *+html " . $matches[0] . "\n";
    }
  }
  return $replacement;
}