Commit
·
de92022
1
Parent(s):
904ec1b
Delete file_compressor.py
Browse files- file_compressor.py +0 -29
file_compressor.py
DELETED
|
@@ -1,29 +0,0 @@
|
|
| 1 |
-
from pathlib import Path
|
| 2 |
-
from PIL import Image
|
| 3 |
-
|
| 4 |
-
Image.MAX_IMAGE_PIXELS = 1000000000
|
| 5 |
-
|
| 6 |
-
def resize_image(file_path, scale_percent):
|
| 7 |
-
with Image.open(file_path) as img:
|
| 8 |
-
width, height = img.size
|
| 9 |
-
new_width = int(width * scale_percent / 100)
|
| 10 |
-
new_height = int(height * scale_percent / 100)
|
| 11 |
-
img_resized = img.resize((new_width, new_height))
|
| 12 |
-
return img_resized
|
| 13 |
-
|
| 14 |
-
def process_files_in_directory(directory_path, size_threshold, scale_percent):
|
| 15 |
-
dir_path = Path(directory_path)
|
| 16 |
-
for file_path in dir_path.glob('*.png'):
|
| 17 |
-
file_size = file_path.stat().st_size
|
| 18 |
-
if file_size >= size_threshold:
|
| 19 |
-
img_resized = resize_image(file_path, scale_percent)
|
| 20 |
-
img_resized.save(file_path)
|
| 21 |
-
resized_file_size = file_path.stat().st_size # リサイズ後のファイルサイズを取得
|
| 22 |
-
print(f"Resized and saved {file_path} with new size: {resized_file_size} bytes")
|
| 23 |
-
|
| 24 |
-
if __name__ == "__main__":
|
| 25 |
-
directory_path = r"E:\Dataset\XXXXXXX" # ここにディレクトリへのパスを入力してください
|
| 26 |
-
size_threshold = 32 * 1024 * 1024 # 32MB
|
| 27 |
-
scale_percent = 50 # 縮小率50%
|
| 28 |
-
|
| 29 |
-
process_files_in_directory(directory_path, size_threshold, scale_percent)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|