|
|
|
@ -1,36 +1,34 @@
|
|
|
|
|
<?php |
|
|
|
|
|
|
|
|
|
$GLOBALS["sprites"] = false; |
|
|
|
|
$GLOBALS['sprites'] = false; |
|
|
|
|
|
|
|
|
|
function sprite ($img, $nom) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Extraire le nom du fichier, soit directement soit dans <img src> |
|
|
|
|
if (@file_exists($img)) $src = $img; |
|
|
|
|
else { |
|
|
|
|
$src = extraire_attribut($img, "src"); |
|
|
|
|
$src = preg_replace(",\?[0-9]*$,", "", $src); |
|
|
|
|
// Si pas de fichier, ignorer |
|
|
|
|
if (!@file_exists($src)) return; |
|
|
|
|
if (!@file_exists($src)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$GLOBALS["sprites"]["$nom"]["fichiers"][] = $src; |
|
|
|
|
|
|
|
|
|
$GLOBALS['sprites']["$nom"]["fichiers"][] = $src; |
|
|
|
|
|
|
|
|
|
$largeur = largeur($img); |
|
|
|
|
$hauteur = hauteur($img); |
|
|
|
|
|
|
|
|
|
if ($largeur > $GLOBALS["sprites"]["$nom"]["largeur"]) $GLOBALS["sprites"]["$nom"]["largeur"] = $largeur; |
|
|
|
|
$hauteur_old = max(0, $GLOBALS["sprites"]["$nom"]["hauteur"]); |
|
|
|
|
$GLOBALS["sprites"]["$nom"]["hauteur"] += $hauteur; |
|
|
|
|
|
|
|
|
|
if ($largeur > $GLOBALS['sprites']["$nom"]["largeur"]) $GLOBALS['sprites']["$nom"]["largeur"] = $largeur; |
|
|
|
|
$hauteur_old = max(0, $GLOBALS['sprites']["$nom"]["hauteur"]); |
|
|
|
|
$GLOBALS['sprites']["$nom"]["hauteur"] += $hauteur; |
|
|
|
|
|
|
|
|
|
$alt = extraire_attribut($img, "alt"); |
|
|
|
|
$class = extraire_attribut($img, "class"); |
|
|
|
|
$fichier = sous_repertoire(_DIR_VAR, 'cache-sprites').$nom; |
|
|
|
|
//$fichier .= "?m=spiprempdate[$fichier]"; |
|
|
|
|
|
|
|
|
|
$date_src = @filemtime($src); |
|
|
|
|
if ($date_src > $GLOBALS["sprites"]["$nom"]["date"]) $GLOBALS["sprites"]["$nom"]["date"] = $date_src; |
|
|
|
|
if ($date_src > $GLOBALS['sprites']["$nom"]["date"]) $GLOBALS['sprites']["$nom"]["date"] = $date_src; |
|
|
|
|
|
|
|
|
|
return "<img src='".find_in_path("rien.gif")."' width='".$largeur."px' height='".$hauteur."px' style='width: ".$largeur."px; height: ".$hauteur."px; background: url($fichier) 0px -".$hauteur_old."px;' alt='$alt' class='$class' />"; |
|
|
|
|
} |
|
|
|
@ -46,21 +44,22 @@ function creer_sprites_terminaison_fichier_image($fichier) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function creer_sprites($flux) { |
|
|
|
|
$sprites = $GLOBALS["sprites"]; |
|
|
|
|
$sprites = $GLOBALS['sprites']; |
|
|
|
|
$page = $flux['data']['texte']; |
|
|
|
|
if ($sprites) { |
|
|
|
|
foreach($sprites as $key => $sprite) { |
|
|
|
|
$fichier = sous_repertoire(_DIR_VAR, 'cache-sprites').$key; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$fichier_sprite = sous_repertoire(_DIR_VAR, 'cache-sprites').$key; |
|
|
|
|
$ext = creer_sprites_terminaison_fichier_image($fichier_sprite); |
|
|
|
|
$nom_fichier_sprite = substr($fichier_sprite, 0, strlen($fichier_sprite) - 4); |
|
|
|
|
|
|
|
|
|
$date_max = $sprite["date"]; |
|
|
|
|
$date_src = @filemtime($fichier); |
|
|
|
|
$date_src = @filemtime($fichier_sprite); |
|
|
|
|
$largeur = $sprite["largeur"]; |
|
|
|
|
$hauteur = $sprite["hauteur"]; |
|
|
|
|
|
|
|
|
|
$creer = false; |
|
|
|
|
if ($date_src < $date_max) $creer = true; |
|
|
|
|
if ($largeur != largeur($fichier) || $hauteur != hauteur ($fichier)) $creer = true; |
|
|
|
|
if ($largeur != largeur($fichier_sprite) || $hauteur != hauteur ($fichier_sprite)) $creer = true; |
|
|
|
|
|
|
|
|
|
if (in_array($_GET['var_mode'], array('recalcul', 'debug'))) $creer = true; |
|
|
|
|
|
|
|
|
@ -74,36 +73,31 @@ function creer_sprites($flux) {
|
|
|
|
|
@imagesavealpha($im,true); |
|
|
|
|
$color_t = imagecolorallocatealpha( $im, 0, 0, 0 , 127 ); |
|
|
|
|
imagefill ($im, 0, 0, $color_t); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$y_total = 0; |
|
|
|
|
foreach($sprite["fichiers"] as $img) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$f = "imagecreatefrom".str_replace("jpg","jpeg",creer_sprites_terminaison_fichier_image($img)); |
|
|
|
|
$im_ = $f($img); |
|
|
|
|
@imagepalettetotruecolor($im_); |
|
|
|
|
|
|
|
|
|
$x = imagesx($im_); |
|
|
|
|
$y = imagesy($im_); |
|
|
|
|
$im_tmp = $f($img); |
|
|
|
|
@imagepalettetotruecolor($im_tmp); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ImageCopy($im, $im_, 0, $y_total, 0, 0, $x, $y); |
|
|
|
|
$x = imagesx($im_tmp); |
|
|
|
|
$y = imagesy($im_tmp); |
|
|
|
|
|
|
|
|
|
@ImageCopy($im, $im_tmp, 0, $y_total, 0, 0, $x, $y); |
|
|
|
|
$y_total += $y; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$nom_fichier = substr($fichier, 0, strlen($fichier) - 4); |
|
|
|
|
_image_imagepng($im, "$nom_fichier.png"); |
|
|
|
|
$f = creer_sprites_terminaison_fichier_image($fichier); |
|
|
|
|
if ($f != "png") { |
|
|
|
|
$new = extraire_attribut( image_aplatir("$nom_fichier.png", $f, "ffffff"), "src"); |
|
|
|
|
@copy($new, $fichier); |
|
|
|
|
|
|
|
|
|
_image_imagepng($im, "$nom_fichier_sprite.png"); |
|
|
|
|
|
|
|
|
|
$ext = creer_sprites_terminaison_fichier_image($fichier_sprite); |
|
|
|
|
if ($ext != "png") { |
|
|
|
|
$new = extraire_attribut( image_aplatir("$nom_fichier_sprite.png", $ext, "ffffff"), "src"); |
|
|
|
|
$ok = copy($new, $fichier_sprite); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
imagedestroy($im); |
|
|
|
|
imagedestroy($im_); |
|
|
|
|
|
|
|
|
|
imagedestroy($im_tmp); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -111,14 +105,14 @@ function creer_sprites($flux) {
|
|
|
|
|
$page = preg_replace_callback(",spiprempdate\[([^\]]*)\],", "creer_sprites_remplacer_date", $page); |
|
|
|
|
|
|
|
|
|
$flux["data"]['texte'] = $page; |
|
|
|
|
$GLOBALS["sprites"] = false; |
|
|
|
|
$GLOBALS['sprites'] = false; |
|
|
|
|
return $flux; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function creer_sprites_remplacer_date($regs) { |
|
|
|
|
$fichier = $regs[1]; |
|
|
|
|
|
|
|
|
|
static $date_fichier=array(); // AJOUT JLUC |
|
|
|
|
if ($date_fichier["$fichier"] > 0) { |
|
|
|
|
return $date_fichier["$fichier"]; |
|
|
|
|
} |
|
|
|
@ -130,9 +124,10 @@ function creer_sprites_remplacer_date($regs) {
|
|
|
|
|
|
|
|
|
|
function creer_sprites_recuperer_fond ($flux) { |
|
|
|
|
if (isset($flux['args']['fond']) |
|
|
|
|
and ($flux['args']['fond'] == 'modeles/logo' |
|
|
|
|
and ($flux['args']['fond'] == "modeles/logo" |
|
|
|
|
or ($flux['args']['fond'] == 'modeles/lesauteurs'))) { |
|
|
|
|
return $flux; |
|
|
|
|
} |
|
|
|
|
return creer_sprites($flux); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|