first
This commit is contained in:
commit
86769c9aaa
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
myvenv
|
14
README.md
Normal file
14
README.md
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Sizer
|
||||||
|
|
||||||
|
A script for sorting pictures (namely, wallpapers) by size.
|
||||||
|
|
||||||
|
It looks for a folder named "wallpapers" in its directory. It then moves all pictures into folders it creates, depending on their size. All pictures that do not fit either a predefined format go in the "SD" folder.
|
||||||
|
|
||||||
|
# Formats
|
||||||
|
## 16:9
|
||||||
|
* hd (1920 x 1080)
|
||||||
|
* 2k (2560 x 1440)
|
||||||
|
* 4k (4096 x 2160)
|
||||||
|
|
||||||
|
# 21:9
|
||||||
|
* 2k (3440 x 1440)
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
opencv-python
|
58
sizer.py
Executable file
58
sizer.py
Executable file
@ -0,0 +1,58 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
#coding: utf-8
|
||||||
|
import cv2
|
||||||
|
import os
|
||||||
|
from os.path import join
|
||||||
|
|
||||||
|
def pic_size_find(pic_path: str):
|
||||||
|
img = cv2.imread(pic_path,0)
|
||||||
|
h, w = img.shape[:2]
|
||||||
|
return(w, h)
|
||||||
|
|
||||||
|
def pics_list(path:os.path):
|
||||||
|
files = [f for f in os.listdir(path) if (f.endswith(".jpg") or f.endswith(".jpeg") or f.endswith(".png"))]
|
||||||
|
|
||||||
|
return files
|
||||||
|
|
||||||
|
def file_move(file, dest):
|
||||||
|
os.rename(file, dest)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
folder4k = "wallpapers4k"
|
||||||
|
folder2k = "wallpapers2k"
|
||||||
|
folderhd = "wallpapershd"
|
||||||
|
foldersd = "wallpaperssd"
|
||||||
|
|
||||||
|
res4k = (4096, 2160)
|
||||||
|
res2k = (2560, 1440)
|
||||||
|
reshd = (1920, 1080)
|
||||||
|
|
||||||
|
for folder in [folder4k, folder2k, folderhd, foldersd]:
|
||||||
|
os.makedirs(join(".", folder), exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
|
files = pics_list("./wallpapers")
|
||||||
|
for f in files:
|
||||||
|
f_path = join("wallpapers", f)
|
||||||
|
size = pic_size_find(f_path)
|
||||||
|
print(f"{f} => {size}")
|
||||||
|
if size == res4k:
|
||||||
|
file_move(f_path, join(folder4k, f))
|
||||||
|
dest_folder = folder4k
|
||||||
|
elif size == res2k:
|
||||||
|
file_move(f_path, join(folder2k, f))
|
||||||
|
dest_folder = folder2k
|
||||||
|
elif size == reshd:
|
||||||
|
file_move(f_path, join(folderhd, f))
|
||||||
|
dest_folder = folderhd
|
||||||
|
else:
|
||||||
|
file_move(f_path, join(foldersd, f))
|
||||||
|
dest_folder = foldersd
|
||||||
|
print(f"{f} moved to {dest_folder}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user