Skip to content

Commit

Permalink
Fix - IE 6, 7 fails to read background attribute values if datauri is…
Browse files Browse the repository at this point in the history
… too long
  • Loading branch information
josephj committed Feb 9, 2011
1 parent 671a8c4 commit 1560175
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions dataurize
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ $mhtml_path = ($separate) ? $base . $separate : $base . basename($output);
// Fetch all the background image attributes using RegExp.
$content = file_get_contents($input);
//echo "/* Original File Size: " . filesize($input) . " */\n";
$pattern = '/background[^:]*:[^;}]*url\(([^\)]+)\)([^;}]*)/';
$pattern = '/background[^:]*:([^;}]*)url\(([^\)]+)\)([^;}]*)/';
preg_match_all($pattern, $content, $data);
$attrs = $data[0];
$urls = $data[1];
$props = $data[2];
$attrs = $data[0];
$props_start = $data[1];
$urls = $data[2];
$props_end = $data[3];
$urls = array_unique($urls);
$data = array();
$uris = array();
Expand Down Expand Up @@ -224,7 +225,7 @@ foreach ($attrs as $attr)
// Save Data URI strings into working array.
$uri = str_replace($url, "\"data:image/$type;base64," . $encode . "\"", $attr);
$url = ($is_mhtml) ? "mhtml:{$mhtml_path}!{$key}" : $url;
$uris[] = $uri . ";*background:url($url){$props[$i]}";
$uris[] = $uri . ";*background:{$props_start[$i]}url($url){$props_end[$i]}";
$new_attrs[] = $attr;
break;
}
Expand Down

0 comments on commit 1560175

Please sign in to comment.