= filemtime($source)) { return $dest; // Миниатюра уже актуальна } $info = getimagesize($source); if (!$info) return false; list($orig_width, $orig_height, $type) = $info; // Определяем тип изображения switch ($type) { case IMAGETYPE_JPEG: $img = imagecreatefromjpeg($source); break; case IMAGETYPE_PNG: $img = imagecreatefrompng($source); break; case IMAGETYPE_GIF: $img = imagecreatefromgif($source); break; case IMAGETYPE_WEBP: $img = imagecreatefromwebp($source); break; default: return false; } // Вычисляем пропорции $ratio = min($width / $orig_width, $height / $orig_height); $new_width = round($orig_width * $ratio); $new_height = round($orig_height * $ratio); // Создаем новое изображение $thumb = imagecreatetruecolor($width, $height); $white = imagecolorallocate($thumb, 255, 255, 255); imagefill($thumb, 0, 0, $white); // Копируем и изменяем размер $x_offset = ($width - $new_width) / 2; $y_offset = ($height - $new_height) / 2; imagecopyresampled($thumb, $img, $x_offset, $y_offset, 0, 0, $new_width, $new_height, $orig_width, $orig_height); // Сохраняем миниатюру switch ($type) { case IMAGETYPE_JPEG: imagejpeg($thumb, $dest, 85); break; case IMAGETYPE_PNG: imagepng($thumb, $dest, 8); break; case IMAGETYPE_GIF: imagegif($thumb, $dest); break; case IMAGETYPE_WEBP: imagewebp($thumb, $dest, 85); break; } imagedestroy($img); imagedestroy($thumb); return $dest; } // Получаем список фото $photos = []; if (is_dir($photos_dir)) { $files = scandir($photos_dir); foreach ($files as $file) { if ($file === '.' || $file === '..') continue; $path = $photos_dir . '/' . $file; $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION)); if (in_array($ext, $allowed_extensions) && is_file($path)) { // Создаем миниатюру $thumb_name = 'thumbs/' . md5($path) . '.jpg'; $thumb_path = create_thumbnail($path, $thumb_name, $thumb_width, $thumb_height); if ($thumb_path) { $photos[] = [ 'full' => $path, 'thumb' => $thumb_path, 'name' => $file, 'size' => filesize($path), 'modified' => filemtime($path), 'exif' => function_exists('exif_read_data') ? @exif_read_data($path) : null ]; } } } } // Сортируем по дате изменения (новые сначала) usort($photos, function($a, $b) { return $b['modified'] - $a['modified']; }); // HTML страница ?>
Все ваши воспоминания в одном месте
Добавьте изображения в папку