"/Users/ace/Downloads/ass"에서 이미지 파일들을 불러와서 이미지 해상도 가로세로합이 7000보다 높으면 "/Users/ace/Downloads/무제 폴더/7000"폴더, 7000보다 낮고 5000보다 크면 "/Users/ace/Downloads/무제 폴더/5000"폴더, 5000보다 낮고 3500보다 크면 "/Users/ace/Downloads/무제 폴더/3500" 폴더로 각각 파일을 옮기는 프로그램
import os
from PIL import Image
# Set the directory where the images are located
image_dir = "/Users/ace/Downloads/ass"
# Set the destination directories
dest_7000 = "/Users/ace/Downloads/무제 폴더/7000"
dest_5000 = "/Users/ace/Downloads/무제 폴더/5000"
dest_3500 = "/Users/ace/Downloads/무제 폴더/3500"
# Iterate through the images in the directory
for filename in os.listdir(image_dir):
# Open the image
with Image.open(os.path.join(image_dir, filename)) as im:
# Get the image resolution
width, height = im.size
# Check the image resolution and move the file to the appropriate directory
if width * height > 7000 * 7000:
os.rename(os.path.join(image_dir, filename), os.path.join(dest_7000, filename))
elif width * height > 5000 * 5000:
os.rename(os.path.join(image_dir, filename), os.path.join(dest_5000, filename))
elif width * height > 3500 * 3500:
os.rename(os.path.join(image_dir, filename), os.path.join(dest_3500, filename))
- dc official App
width * height > 3500 * 3500: 이거 의미가 뭐임 3500보다 작은건데 3500+3500임??
넓이가 저거보다 넓으면
가로세로합이 잘못됨.. width + height > 7000 처럼 바꿔줘야 될 듯..
Ukeysoft % /usr/local/bin/python3 /Users/ace/Documents/Ukeysoft/imgRes.py Traceback (most recent call last): File "/Users/ace/Documents/Ukeysoft/imgRes.py", line 15, in <module> with Image.open(os.path.join(image_dir, filename)) as im: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/PIL/Image.py", line 3186, in open raise UnidentifiedImageError( PIL.UnidentifiedImageError: cannot identify image file '/Users/ace/Downloads/무제 폴더/.DS_Store'
이게 무슨 의미임 어디가 잘못된가
저 코드는 디렉토리 경로 상의 모든 파일/폴더를 읽어옴. 그래서 이미지 파일이 아닌건 못 읽는거임.
그럼 어떻게 해야됨 heif같은건 읽을 수가 있음?
초보에게 제일 적합한 방법은 glob이나 imutils를 이용해서 이미지 파일만 읽는 리스트를 만드는 것임. 근데 코딩을 모르는거 같아서 구체적으로 얘기해주기가 귀찮어..
heif가 뭔데..
그래도 거의 완벽하네..
가로세로합이 8000이상인건 7000폴더에 안가는데 어캐해야됨
조금만 만져주면 되잖아
그럼 줄만 알려주셈
새로 쓴 글 확인 ㄱㄱ