[Xfce4-commits] <www:xfce-4.10> Also inline the jpg.

Nick Schermer noreply at xfce.org
Tue Apr 17 18:20:01 CEST 2012


Updating branch refs/heads/xfce-4.10
         to b3b384b14b40262893e8d6cb545b0896dbaff9bb (commit)
       from ebcb154c61e299f5b4711983735f2b9ee05a46b7 (commit)

commit b3b384b14b40262893e8d6cb545b0896dbaff9bb
Author: Nick Schermer <nick at xfce.org>
Date:   Tue Apr 17 18:12:55 2012 +0200

    Also inline the jpg.
    
    Saves a file transfer and 12% data.

 style/css.php |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/style/css.php b/style/css.php
index 3f49996..b552962 100644
--- a/style/css.php
+++ b/style/css.php
@@ -20,14 +20,14 @@ function write_header ($mtime)
 function base64data ($matches)
 {
   $file = $matches[1] .'.'. $matches[2];
-  $size = filesize ($file);
-  if ($size > 0)
-  {
-    $imgbinary = fread (fopen ($file, "r"), $size);
-    $base64 = base64_encode ($imgbinary);
-    
-    return "url('data:image/".$matches[2].";base64,$base64')";
-  }
+  
+  $buf = file_get_contents ($file);
+  if ($buf != false)
+    {
+      return 'url(\'data:image/'.
+                  $matches[2].';base64,'.
+                  base64_encode ($buf).'\')';
+    }
 
   return $matches[0];
 }
@@ -70,7 +70,7 @@ $buf = str_replace (array (': ', ' {', ', '), array (':', '{', ','), $buf); /* c
 $buf = str_replace (array ("\r\n", "\r", "\n", "\t", '  '), '', $buf); /* strip lines and spaces */
 
 /* embed images in css */
-$buf = preg_replace_callback ('!url\(\'([a-z/]*?).(png|gif)\'\)!', 'base64data', $buf);
+$buf = preg_replace_callback ('!url\(\'([a-z/-]*?).(png|gif|jpg)\'\)!', 'base64data', $buf);
 
 /* output */
 write_header ($mtime);


More information about the Xfce4-commits mailing list