[英]How can I save lots of images after resizing them all into another directory in Python(PIL)?
[英]How do I search through images in the directory and save them into another folder?
假設有一個文件夾,其中包含 10,000 張圖像。
我有一個abc.text
文件,其中有 400 行,每行包含一個圖像名稱,總共 400 個圖像。
這些圖像位於該圖像文件夾中。
text file
是這樣的:
UIO 15 09:5522:106 XOP UIO[24371]: 1525-522-15220 1555:068524:167855 INFO Filename: 1852585.jpeg
UIO 15 52522:2505:106 XOP UIO[52585]: 1525-522-152920 1555:068524:167855 INFO Filename: 1052520.jpeg
我想從該文本文件中讀取所有圖像,在該圖像文件夾中找到它們並將它們以相同的名稱保存到一個新目錄中。
我想知道我是否可以自動化這個? 有什么辦法可以快速完成嗎?
你可以這樣做:
cat /path_to_text_file.txt | awk '{print $10}' | xargs -i cp /path_to_image_folder/{} /path_to_dest_dir
import glob
import os,shutil
images_list=glob.glob(PATH/OF/IMAGES/*.jpg)
file=open(PATH.txt,"r").read().split(/n)
for image_name in file:
if image_name in images_list:
shutils.copyfile(image_name,"NEWFOLDER/"+image_name)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.