function _css_emimage_replace in CSS Embedded Images 7
Same name and namespace in other branches
- 6.2 css_emimage.module \_css_emimage_replace()
- 6 css_emimage.module \_css_emimage_replace()
preg_replace_callback() callback to replace URLs with data URIs.
2 string references to '_css_emimage_replace'
- _css_emimage_process in ./
css_emimage.module - Helper function to replace URLs with data URIs.
- _css_emimage_text_processor in ./
css_emimage.advagg.inc - Process the css text and replace it with image data where necessary.
File
- ./
css_emimage.inc, line 74 - CSS Embedded Images module.
Code
function _css_emimage_replace($matches) {
list($declaration, $selector, $properties) = $matches;
$pattern = '/(background(?:-image)?|list-style(?:-image)?):[^{};)]*?((?:none|url\\([\'"]?(.+?)[\'"]?\\)))([^{};]*)/i';
preg_match_all($pattern, $properties, $matches);
foreach ($matches[1] as $i => $property) {
$url = $matches[2][$i];
$file = $matches[3][$i];
$important = stripos($matches[4][$i], '!important') !== FALSE;
if ($file && strpos($file, base_path()) === 0 && ($image = image_get_info($file = substr($file, strlen(base_path()))))) {
$ielimit = variable_get('css_emimage_ielimit', 1);
// only embed data URIs less than 32KB, thanks IE
if ($ielimit && $image['file_size'] * 1.3333 >= CSS_EMIMAGE_IE_DATAURI_LIMIT) {
$image = NULL;
}
$token = _css_emimage_collect(array(
$selector,
$property,
$url,
$file,
$important,
$image,
));
$declaration = str_replace($url, $token, $declaration);
}
else {
_css_emimage_collect(array(
$selector,
$property,
$url,
$file,
$important,
NULL,
));
}
}
return $declaration;
}