diff --git a/photos.php b/photos.php index f2ec180..b9086dc 100644 --- a/photos.php +++ b/photos.php @@ -70,7 +70,7 @@ function getPhotos($dir) $path = realpath($dir.DIRECTORY_SEPARATOR.$value); if (!is_dir($path)) { $ext = pathinfo($path, PATHINFO_EXTENSION); - if ($ext == "bmp" || $ext == "jpg" || $ext == "jpeg" || $ext == "png" || $ext == "gif") { + if ($ext == "jpg" || $ext == "jpeg" || $ext == "png") { $imageSrc = $dir.DIRECTORY_SEPARATOR.$value; $imageId = "photo-".$displayedItems; include("includes/photos/photo_template.php"); diff --git a/photos/compress_photos.py b/photos/compress_photos.py index ed34638..2ff4a90 100644 --- a/photos/compress_photos.py +++ b/photos/compress_photos.py @@ -15,9 +15,9 @@ def get_images(path): """ file_list = [] for root, dirs, files in os.walk(path): - if is_directory_valid(root, len(files)): + if is_directory_valid(root, files): for fn in files: - if fn.endswith("png") or fn.endswith("jpg") or fn.endswith("bmp"): + if is_file_valid_image(fn): file_list.append(os.path.join(root, fn)) return file_list @@ -59,7 +59,8 @@ def compress_images(images): sys.exit("Fatal : Directory '" + os.path.dirname(filename) + "' does not exist and cannot be created") img.save(filename, "JPEG") - print("Done. Thumbnails saved in 'photos_thumb' directory") + print("done") + print("Thumbnails saved in 'photos_thumb' directory") def get_new_path(img): @@ -73,18 +74,18 @@ def get_new_path(img): def zip_dir(path): """ - Compress files in the specified directory and sub-directories + Compress images in the specified directory and sub-directories Create one zip per folder :param path: directory to get files in :return: """ for root, dirs, files in os.walk(path): - if is_directory_valid(root, len(files)): + if is_directory_valid(root, files): print("Compressing '" + root + "'", end="") with ZipFile(os.path.join(root, get_current_dir(root)) + ".zip", "w", ZIP_DEFLATED) as zip_file: for fn in files: - if not fn.endswith("zip"): + if not fn.endswith("zip") and is_file_valid_image(fn): print(".", end="") absolute_file_name = os.path.join(root, fn) zippped_file_name = absolute_file_name[len(root)+len(os.sep):] # XXX: relative path @@ -93,22 +94,32 @@ def zip_dir(path): print("COMPRESSION FINISHED") -def is_directory_valid(path, files_number): +def is_directory_valid(path, files): """ - Check if the given path is not hidden or empty - :param files_number: number of files in the folder + Check if the given path is not hidden or without images + :param files: files in the folder :param path: Path to check :return: True if path contains a hidden folder or is empty, False otherwise """ directories = path.split(os.sep) - valid = files_number > 0 - for dn in directories: + valid = len(files) > 0 + for dn in directories: # check if directory or one of its parent are not hidden if dn.startswith(".") or not valid: valid = False break + if valid: + valid_files = [] + for fn in files: # check if directory contains valid images + if is_file_valid_image(fn): + valid_files.append(fn) + valid = len(valid_files) > 0 return valid +def is_file_valid_image(file): + return file.endswith("png") or file.endswith("jpg") or file.endswith("jpeg") + + def get_current_dir(path): """ Get the name of the current directory @@ -126,7 +137,7 @@ def get_confirmation(path): """ print("The following folders will be compressed (hidden and empty folders are ignored):") for root, dirs, files in os.walk(path): - if is_directory_valid(root, len(files)): + if is_directory_valid(root, files): print(root) confirmation = input("Are you sure you want to proceed? [Y/n]") return confirmation == "Y" or confirmation == "y"