3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2020 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
14 * Fonctions pour embarquer des images dans un CSS
16 * @package SPIP\Compresseur\Embarquer
18 if (!defined('_ECRIRE_INC_VERSION')) {
23 * Embarque en base64 les images png|gif|jpg présentes dans un fichier CSS
25 * Extrait les images décrites par 'url(...)' d'un fichier CSS pour
26 * les faire embarquer directement dans le fichier
28 * @see filtre_embarque_fichier()
30 * @param string $contenu
31 * Contenu d'un fichier CSS
32 * @param string $source
33 * URL Source de ce fichier CSS
34 * @param string $source_file
35 * filename Source de ce fichier CSS, si connu
37 * Contenu du fichier CSS avec les images embarquées
39 function compresseur_embarquer_images_css($contenu, $source, $source_file = null) {
40 #$path = suivre_lien(url_absolue($source),'./');
41 $base = ($source_file ?
$source_file : $source);
42 $base = ((substr($base, -1) == '/') ?
$base : (dirname($base) . '/'));
43 $filtre_embarque_fichier = chercher_filtre('filtre_embarque_fichier');
44 if (!defined('_CSS_EMBARQUE_FICHIER_MAX_SIZE')) {
45 define('_CSS_EMBARQUE_FICHIER_MAX_SIZE', 4 * 1024);
48 return preg_replace_callback(
49 ",url\s*\(\s*['\"]?([^'\"/][^:]*[.](png|gif|jpg))['\"]?\s*\),Uims",
50 function($x) use ($filtre_embarque_fichier, $base) {
51 return "url(\"" . $filtre_embarque_fichier($x[1], $base, _CSS_EMBARQUE_FICHIER_MAX_SIZE
) . "\");";
60 * Embarquer des images dans les css, tous nav :
63 * Content-Type: multipart/related; boundary="_ANY_STRING_WILL_DO_AS_A_SEPARATOR"
65 * --_ANY_STRING_WILL_DO_AS_A_SEPARATOR
66 * Content-Location:chevron
67 * Content-Transfer-Encoding:base64
69 * iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFAQMAAAC3obSmAAAABlBMVEX///9mZmaO7mygAAAAEElEQVR42mNYwBDAoAHECwAKMgIJXa7xqgAAAABJRU5ErkJggg==
71 * --_ANY_STRING_WILL_DO_AS_A_SEPARATOR
74 * --_ANY_STRING_WILL_DO_AS_A_SEPARATOR
79 * background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFAQMAAAC3obSmAAAABlBMVEX///9mZmaO7mygAAAAEElEQVR42mNYwBDAoAHECwAKMgIJXa7xqgAAAABJRU5ErkJggg==");
80 *background-image:url(mhtml:urlfeuille.css!chevron)}