พอดีจะหาไอเดียทำกราฟใส่เปเปอร์ ปกติก็จะนั่งเปิดอ่านทีละอัน นั่งcropอันที่ชอบละsaveเก็บไว้ในfolderบ้าง แปะใน powerpoint/excel บ้างแล้วแต่อารมณ์ เสร็จละก็มักจะหาไม่เจอว่ารูปนี้มาจากเปเปอร์ไหน….
ด้วยความขี้เกียจcropรูปละ เลยเซิร์จหาโปรแกรมละก็เจอ มีให้ดาวโหลดโปรแกรมลงคอมด้วยนะ
https://tools.pdf24.org/en/extract-images
คือลากไฟล์เยอะๆใส่ได้เลย ละมันจะextractรูปภาพออมาให้ ตอนที่เซฟยังแยกโฟลเดอร์ตามชื่อ paper อยู่ โชคดีที่ชื่อรูปยังมี prefix เป็นชื่อโฟลเดอร์อยู่ (ถ้าทำในเว็ป ชื่อรูปไม่มี prefix เป็น 0.png 1.png 2.png ไป)
เดี่ยวเขียน python ให้มันเอารูปออกมาจากโฟลเดอร์จะได้ดูง่ายๆ ถาม chatgpt กับเขียนเพิ่มเองอีกนิด
![](http://mionzwp.bumbleplay.com/wp-content/uploads/2024/01/image-1024x752.png)
![](http://mionzwp.bumbleplay.com/wp-content/uploads/2024/01/image-1.png)
import os
import shutil
from pathlib import Path
def move_images_and_delete_folders(folder_path):
print("process on :"+folder_path)
# Get a list of all subdirectories
subdirectories = [f for f in os.listdir(folder_path) if os.path.isdir(os.path.join(folder_path, f))]
# Iterate through each subdirectory
for subdir in subdirectories:
print(subdir)
subdir_path = os.path.join(folder_path, subdir)
if not os.path.isdir(subdir_path):
print("not a directory, skip!")
continue
# Get a list of all files in the subdirectory
files = [f for f in os.listdir(subdir_path) if os.path.isfile(os.path.join(subdir_path, f))]
folder_contain_image = False
# Iterate through each file in the subdirectory
for file in files:
# Check if the file is an image (you can customize this check based on your file extensions)
if file.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')):
# Move the image file to the parent directory
source_file = os.path.join(subdir_path, file)
destination_file = os.path.join(folder_path, file)
shutil.move(source_file, destination_file)
folder_contain_image=True
# Delete the empty subdirectory
if(folder_contain_image):
os.rmdir(subdir_path)
# Replace 'your_folder_path' with the path to the folder containing subfolders
folder_path = os.getcwd()
move_images_and_delete_folders(folder_path)
![](http://mionzwp.bumbleplay.com/wp-content/uploads/2024/01/image-2.png)