<?php
/*
Copyright 2007 Hugo Wood
This file is part of HAE.
HAE is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
HAE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
*/
?>
<?php
$i = 0;
$rec = "../../";
$exeptions = array("db", "php", "css", "js", "hae", "dev", "admin", "Folder.jpg", "System Volume Information", "RECYCLER"); // liste des fichiers et extensions a ne pas afficher
createcache("./", $rec, true);
echo "<br /><br />Thumbnail caching completed<br /><br />";
function createcache($dir, $rec, $cont=false, $createmini=true) {
global $i;
global $exeptions;
$path = $dir;
$dir = opendir($rec.$dir);
while($f = readdir($dir)) {
if($f==".") {
}
elseif($f=="..") {
}
elseif(is_dir($rec.$path.$f) && !in_array(get_ext($f), $exeptions) && !in_array($f, $exeptions)) {
echo "Directory : ",$path.$f,"/<br />\n";
$dir2 = opendir($rec.$path.$f."/");
while($f2 = readdir($dir2)) {
if ($f2==".htaccess") {
echo "HTACCESS --> no thumnail for this directory\n";
$createmini = false;
}
}
closedir($dir2);
createcache($path.$f."/", $rec, true, $createmini);
}
elseif(is_file($rec.$path.$f) && $createmini && !in_array(get_ext($f), $exeptions) && !in_array($f, $exeptions) && !preg_match('#^\.#', $f) && !preg_match('#^AlbumArt#', $f)) {
if (get_ext($f) == "jpg" || get_ext($f) == "jpeg") {
echo $i.") ".$path.$f,"<br />\n";
$i++;
setDirTree("../cache/24/".$path);
setDirTree("../cache/64/".$path);
setDirTree("../cache/128/".$path);
setDirTree("../cache/192/".$path);
if ($cont==true) {
if (file_exists("../cache/24/".$path.$f.".png")==false) {
size($path.$f, 24, $f, "jpeg", $rec);
}
if (file_exists("../cache/64/".$path.$f.".png")==false) {
size($path.$f, 64, $f, "jpeg", $rec);
}
if (file_exists("../cache/128/".$path.$f.".png")==false) {
size($path.$f, 128, $f, "jpeg", $rec);
}
if (file_exists("../cache/192/".$path.$f.".png")==false) {
size($path.$f, 192, $f, "jpeg", $rec);
}
}
}
elseif (get_ext($f) == "png") {
echo $i.") ".$path.$f,"<br />\n";
$i++;
setDirTree("../cache/24/".$path);
setDirTree("../cache/64/".$path);
setDirTree("../cache/128/".$path);
setDirTree("../cache/192/".$path);
if ($cont==true) {
if (file_exists("../cache/24/".$path.$f.".png")==false) {
size($path.$f, "24", $f, "png", $rec);
}
if (file_exists("../cache/64/".$path.$f.".png")==false) {
size($path.$f, 64, $f, "png", $rec);
}
if (file_exists("../cache/128/".$path.$f.".png")==false) {
size($path.$f, 128, $f, "png", $rec);
}
if (file_exists("../cache/192/".$path.$f.".png")==false){
size($path.$f, 192, $f, "png", $rec);
}
}
}
elseif (get_ext($f) == "gif") {
echo $i.") ".$path.$f,"<br />\n";
$i++;
setDirTree("../cache/24/".$path);
setDirTree("../cache/64/".$path);
setDirTree("../cache/128/".$path);
setDirTree("../cache/192/".$path);
if ($cont==true) {
if (file_exists("../cache/24/".$path.$f.".png")==false) {
size($path.$f, 24, $f, "gif", $rec);
}
if (file_exists("../cache/64/".$path.$f.".png")==false) {
size($path.$f, 64, $f, "gif", $rec);
}
if (file_exists("../cache/128/".$path.$f.".png")==false) {
size($path.$f, 128, $f, "gif", $rec);
}
if (file_exists("../cache/192/".$path.$f.".png")==false){
size($path.$f, 192, $f, "gif", $rec);
}
}
}
}
}
closedir($dir);
}
function setDirTree($_dirTree) {
$path="";
$tabl = explode('/', $_dirTree);
for ($numero = 0; $numero < count($tabl)-1; $numero++){
$f = $tabl[$numero];
if(!is_dir($path.$f)) {
mkdir($path.$f);
}
$path=$path.$f."/";
}
}
function get_ext($file, $case=false) {
$tmp_hash=explode(".",$file);
$ext=$tmp_hash[count($tmp_hash)-1];
if ($case==false) {$ext = strtolower($ext);}
return $ext;
}
function size($fich, $lim, $name, $format, $rec){
$nomFichier = $fich;
$limite = $lim; // L'image est considérée comme miniature en dessous de la taille 100x100 pixels
$size = getimagesize($rec.$nomFichier);
$hauteur = $size[1];
$largeur = $size[0];
if ($hauteur <= $limite && $largeur <= $limite && $lim=="192") {
}
else{
if ($format == "jpeg") {
$source = @imagecreatefromjpeg($rec.$nomFichier); // L'image est la source
if (!$source) {
echo "<br />ERROR cannot open: ".$rec.$nomFichier." --> no thumbnail created (file is not picture)<br /><br />\n";
return false;
}
}
elseif ($format == "png"){
$source = @imagecreatefrompng($rec.$nomFichier); // L'image est la source
if (!$source) {
echo "<br />ERREUR impossible d'ouvrir : ".$rec.$nomFichier." --> no thumbnail created (file is not picture)<br /><br />\n";
return false;
}
}
elseif ($format == "gif"){
$source = @imagecreatefromgif($rec.$nomFichier); // L'image est la source
if (!$source) {
echo "<br />ERREUR impossible d'ouvrir : ".$rec.$nomFichier." --> no thumbnail created (file is not picture)<br /><br />\n";
return false;
}
}
if($hauteur >= $limite AND $hauteur >= $largeur) {// Calcule des dimensions miniatures
$largeur = $largeur / ($hauteur / $limite); // Calcule de la largeur miniature
$hauteur = $limite;
}
else {
$hauteur = $hauteur / ($largeur / $limite); // Calcule de la hauteur miniature
$largeur = $limite;
}
$destination = imagecreatetruecolor($limite, $limite); // On crée la miniature vide
imagealphablending($destination, false);
imagesavealpha($destination, true);
$color = imagecolorallocatealpha($destination, 0, 0 ,0 , 127);
imagefilledrectangle($destination, 0, 0, $limite, $limite, $color);
$largeur_source = imagesx($source); // Largeur de la source
$hauteur_source = imagesy($source); // Hauteur de la source
$largeur_destination = $largeur; // Largeur de la miniature
$hauteur_destination = $hauteur; // Hauteur de la miniature
echo $largeur_destination,'X',$hauteur_destination,'
';
$nomMiniature = '../cache/'.$limite.'/'.$fich.'.png'; // Nom de la miniature
imagecopyresampled($destination, $source, ($limite-$largeur_destination)/2, ($limite-$hauteur_destination)/2, 0, 0, $largeur_destination, $hauteur_destination, $largeur_source, $hauteur_source); // Création de la
imageinterlace ($destination, 1);
imagepng($destination, $nomMiniature, 9); // miniature
echo '<a href="'.utf8_encode($nomFichier).'"><img src="'.utf8_encode($nomMiniature).'" border="0"></a><br />'."\n";
}
}
?>