* @contributors OranginaRouge (orangina-rouge.org) * @link https://github.com/Oros42/KISSGallery * @license CC0 Public Domain * @version 1.8 * @date 2024-04-13 * * Install : * $ sudo apt install php-gd * $ cd // * $ wget https://raw.githubusercontent.com/Oros42/KISSGallery/master/index.php * * KISS : https://en.wikipedia.org/wiki/KISS_principle */ $title = "KISSGallery"; // You can change define("HEIGHT", 300); // You can change define("MAKE_THUMBNAIL", true); // You can change but it's better to leave it to true define("FILE_SORT", "ASC"); // You can change. ascending:"ASC" or descending:"DESC" // You can change the favicon if you want define("FAVICON_PATH", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAL0lEQVQ4y2NkYGD4z0ABYGFgYGD4/x+7GYyMjAyE5JkYKAQDbwDjaCCOBuLwCEQAApMWH3p4gJkAAAAASUVORK5CYII="); //define("FAVICON_PATH", "favicon.png"); define("LIMIT_IMAGE_PER_PAGE", 50); // You can change. Interger > 0 // If the script is run in cli mode (for creating cache) // then we don't show HTML define("SHOW_HTML", php_sapi_name() != "cli"); if (MAKE_THUMBNAIL) { define("TMP_DIR", "./cache/"); // You can change if (!is_dir(TMP_DIR)) { if (!@mkdir(TMP_DIR, 0755)) { die("Can't mkdir ".TMP_DIR); } } if (!function_exists("imagecreatefromjpeg")) { die("sudo apt install php-gd\nOr set MAKE_THUMBNAIL to false"); } } else { define("TMP_DIR", ""); } $allowedExt = ['jpeg', 'png', 'gif', 'bmp', 'wbmp', 'webp', 'xbm']; // Don't change $excludedFiles = ['.gitignore', 'favicon.ico', 'favicon.png', 'index.php', 'LICENSE', 'README.md', 'titles.csv']; $titles = []; // titles of images if (is_file("titles.csv")) { if (($handle = fopen("titles.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) { //$titles[] = ""; $titles[$data[0]] = $data[1]; } fclose($handle); } } function makeThumbnail($file, $ext) { echo "make thumbnail ".$file; if (SHOW_HTML) { ob_flush(); flush(); } list($width, $height) = getimagesize($file); if ($height < 1) { $height = 1; } if ($width < 1) { $width = 1; } $newwidth = $width * (HEIGHT/$height); $imgcreate = "imagecreatefrom".$ext; $src = $imgcreate($file); $dst = imagecreatetruecolor($newwidth, HEIGHT); imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, HEIGHT, $width, $height); // https://www.php.net/manual/en/function.exif-read-data.php#110894 $exif = exif_read_data($file); if(!empty($exif['Orientation'])) { switch($exif['Orientation']) { case 8: $dst = imagerotate($dst,90,0); break; case 3: $dst = imagerotate($dst,180,0); break; case 6: $dst = imagerotate($dst,-90,0); break; } } imageinterlace($dst, true); $imgsave = "image".$ext; if (!$imgsave($dst, TMP_DIR.$file)) { echo " can't save :-/"; $returnStatus = 0; } else { echo " ok"; $returnStatus = 1; } chmod(TMP_DIR.$file, 0755); echo "<br>\n"; return $returnStatus; } if (SHOW_HTML) { ?><!DOCTYPE html> <!-- https://github.com/Oros42/KISSGallery --> <html> <head> <title><?php echo $title; ?> 11) { $exif = exif_imagetype($file); if ($exif > 0) { $ext = substr(image_type_to_extension($exif),1); // don't trust file name ! if (in_array($ext, $allowedExt)) { $totalImg++; if (MAKE_THUMBNAIL && !is_file(TMP_DIR.$file)) { if (makeThumbnail($file, $ext)) { if ($cptImg < LIMIT_IMAGE_PER_PAGE) { $imgListe[] = $file; $cptImg++; } } $needReload = true; } else { if ($startOffset > 0) { $startOffset--; continue; } if ($cptImg < LIMIT_IMAGE_PER_PAGE) { $imgListe[] = $file; $cptImg++; } } } } } } } $nbPages = (int)($totalImg / LIMIT_IMAGE_PER_PAGE); if (SHOW_HTML) { if ($needReload) { echo "Reload
\n"; } echo "
\n"; $i=0; foreach ($imgListe as $img) { if (isset($titles[$img])) { $imgTitle = trim(htmlentities($titles[$img])); } else { $imgTitle = ""; } $img = rawurlencode($img); echo sprintf("\n", $img, $imgTitle, $i, TMP_DIR, $img); $i++; } ?>
0) { echo "
"; if ($page > 0) { echo " \n"; } $initPagePrev = max(0, $page-3); if($initPagePrev > 0){ echo "0 \n"; if ($initPagePrev > 1) { echo " \n"; } } for ($pagePrev=$initPagePrev; $pagePrev < $page; $pagePrev++) { echo "$pagePrev \n"; } echo "[$page] \n"; $endPaging = min($page+4, $nbPages); for ($pageNext=$page+1; $pageNext < $endPaging; $pageNext++) { echo "$pageNext \n"; } if ($page +3 < $nbPages) { echo "\n"; } if($page < $nbPages){ echo "$nbPages\n"; } if ($page<$nbPages) { echo "\n"; } echo "
"; } ?>