Compare commits
9
Commits
c5a3fcb1a0
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b6c4c00f9 | ||
|
|
e962e4bfa6 | ||
|
|
c604d8a768 | ||
|
|
17fb5437c9 | ||
|
|
e7d74c85ec | ||
|
|
f16a20c580 | ||
|
|
95f0f20a0e | ||
|
|
09e7d9410a | ||
|
|
6bf6ae8c97 |
No files matched your search
+14
@@ -0,0 +1,14 @@
|
||||
.DS_Store
|
||||
.idea
|
||||
*.log
|
||||
tmp/
|
||||
|
||||
*.tern-port
|
||||
node_modules/
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
*.tsbuildinfo
|
||||
.npm
|
||||
.eslintcache
|
||||
venv/
|
||||
Regular → Executable
+176
-49
@@ -1,66 +1,193 @@
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from PIL import Image, ImageTk
|
||||
import os
|
||||
#!/usr/bin/env python
|
||||
|
||||
# OOO1.jpg = page de droite
|
||||
# 0002.jpg = page de gauche
|
||||
# 0000.jpg = peut-être page vide ?
|
||||
# 000n.jpg = peut-être page vide ?
|
||||
|
||||
# Faire ces premières modifications, puis on passe aux ajustements luminosité,
|
||||
# contraste, etc
|
||||
#
|
||||
# Puis on fait le PDF puis on OCR.
|
||||
|
||||
# class PIL.ImageTk.PhotoImage(image: Image.Image | str | None = None, size: tuple[int, int] | None = None, **kw: Any)
|
||||
|
||||
# list_of_num = [int(i.split(".")[0]) for i in a]
|
||||
# list_of_num.sort()
|
||||
|
||||
from os import listdir
|
||||
import os
|
||||
import glob
|
||||
import tkinter as tk
|
||||
from tkinter import ttk, filedialog
|
||||
from PIL import Image, ImageTk, ImageEnhance
|
||||
|
||||
parent = tk.Tk()
|
||||
parent.title("Image in Tkinter")
|
||||
parent.title("Perlinator")
|
||||
parent.minsize(320, 240)
|
||||
|
||||
image_files = []
|
||||
|
||||
|
||||
def button_clicked():
|
||||
global isittrue
|
||||
if isittrue == 0:
|
||||
image2 = Image.open("test/ssh.png")
|
||||
image2 = ImageTk.PhotoImage(image2)
|
||||
image_label.configure(image=image2)
|
||||
image_label.image = image2
|
||||
isittrue = 1
|
||||
def upload_folder():
|
||||
folder_path = filedialog.askdirectory()
|
||||
if folder_path:
|
||||
global image_files
|
||||
if not any(
|
||||
f.lower().endswith((".png", ".jpg", ".jpeg")) for f in listdir(folder_path)
|
||||
):
|
||||
popup = tk.Toplevel(parent)
|
||||
popup.title("Attention")
|
||||
popup.geometry("300x100")
|
||||
label = tk.Label(popup, text="Aucune image trouvée dans le dossier.")
|
||||
label.pack(pady=20)
|
||||
popup.after(2000, popup.destroy)
|
||||
return
|
||||
|
||||
image_files = [
|
||||
f
|
||||
for f in listdir(folder_path)
|
||||
if f.lower().endswith((".png", ".jpg", ".jpeg"))
|
||||
]
|
||||
print(f" {len(image_files)} images trouvées dans {folder_path}:")
|
||||
for image_file in image_files:
|
||||
print(image_file)
|
||||
print(image_files)
|
||||
|
||||
open_button.pack_forget()
|
||||
|
||||
else:
|
||||
image_label.configure(image=img)
|
||||
image_label.image = img
|
||||
isittrue = 0
|
||||
popup = tk.Toplevel(parent)
|
||||
popup.title("Attention")
|
||||
popup.geometry("300x100")
|
||||
label = tk.Label(popup, text="Aucun dossier sélectionné.")
|
||||
label.pack(pady=20)
|
||||
popup.after(2000, popup.destroy)
|
||||
|
||||
|
||||
isittrue = 0
|
||||
#
|
||||
#
|
||||
# test logic, not real
|
||||
files = []
|
||||
|
||||
button = tk.Button(
|
||||
parent,
|
||||
text="Click Me",
|
||||
command=button_clicked,
|
||||
activebackground="blue",
|
||||
activeforeground="white",
|
||||
anchor="center",
|
||||
bd=3,
|
||||
bg="lightgray",
|
||||
cursor="hand2",
|
||||
disabledforeground="gray",
|
||||
fg="black",
|
||||
font=("Arial", 12),
|
||||
height=2,
|
||||
highlightbackground="black",
|
||||
highlightcolor="green",
|
||||
highlightthickness=2,
|
||||
justify="center",
|
||||
overrelief="raised",
|
||||
padx=10,
|
||||
pady=5,
|
||||
width=15,
|
||||
wraplength=100,
|
||||
|
||||
def bulk_optimize(
|
||||
source_path: str, dest_path: str, b: float, c: float, s: float
|
||||
) -> None:
|
||||
with Image.open(source_path) as img:
|
||||
brightness = ImageEnhance.Brightness(img)
|
||||
contrast = ImageEnhance.Contrast(img)
|
||||
sharpness = ImageEnhance.Sharpness(img)
|
||||
|
||||
brightness.enhance(b)
|
||||
contrast.enhance(c)
|
||||
sharpness.enhance(s)
|
||||
|
||||
files.append(img)
|
||||
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
paths = Path(".").glob("*.png")
|
||||
for path in paths:
|
||||
bulk_optimize(path, path.stem, 1.0, 0.5, 0.5)
|
||||
# TEST LOGIC END
|
||||
|
||||
b_slider_double = tk.DoubleVar()
|
||||
c_slider_double = tk.DoubleVar()
|
||||
s_slider_double = tk.DoubleVar()
|
||||
|
||||
original_pil_image = Image.open("./test/tux.jpg")
|
||||
img = ImageTk.PhotoImage(original_pil_image)
|
||||
panel = tk.Label(parent, image=img)
|
||||
panel.pack()
|
||||
|
||||
|
||||
def get_sliders():
|
||||
|
||||
pil_img = original_pil_image.copy()
|
||||
|
||||
brightness = ImageEnhance.Brightness(pil_img)
|
||||
pil_img = brightness.enhance(b_slider_double.get() / 100)
|
||||
|
||||
contrast = ImageEnhance.Contrast(pil_img)
|
||||
pil_img = contrast.enhance(c_slider_double.get() / 100)
|
||||
|
||||
sharpness = ImageEnhance.Sharpness(pil_img)
|
||||
pil_img = sharpness.enhance(s_slider_double.get() / 100)
|
||||
|
||||
img = ImageTk.PhotoImage(pil_img)
|
||||
panel.configure(image=img)
|
||||
panel.image = img # Keep a reference to prevent gc
|
||||
|
||||
return (
|
||||
b_slider_double.get() / 100,
|
||||
c_slider_double.get() / 100,
|
||||
s_slider_double.get() / 100,
|
||||
)
|
||||
|
||||
|
||||
b_slider_val, c_slider_val, s_slider_val = get_sliders()
|
||||
|
||||
# 1 to 100 → 0 to 1
|
||||
b_slider = tk.Scale(
|
||||
parent, variable=b_slider_double, from_=0, to=200, orient=tk.HORIZONTAL
|
||||
)
|
||||
c_slider = tk.Scale(
|
||||
parent, variable=c_slider_double, from_=0, to=200, orient=tk.HORIZONTAL
|
||||
)
|
||||
s_slider = tk.Scale(
|
||||
parent, variable=s_slider_double, from_=0, to=200, orient=tk.HORIZONTAL
|
||||
)
|
||||
|
||||
button.pack(padx=20, pady=20)
|
||||
show_enhance_button = tk.Button(
|
||||
parent,
|
||||
text="Preview",
|
||||
command=get_sliders,
|
||||
bg="yellow",
|
||||
)
|
||||
|
||||
folder_dir = "./test/"
|
||||
for images in os.listdir(folder_dir):
|
||||
l1 = tk.Label(parent)
|
||||
|
||||
if images.endswith(".png") or images.endswith(".jpg") or images.endswith(".jpeg"):
|
||||
print(images)
|
||||
b_slider.pack(anchor=tk.CENTER)
|
||||
c_slider.pack(anchor=tk.CENTER)
|
||||
s_slider.pack(anchor=tk.CENTER)
|
||||
|
||||
img = Image.open("test/couv.png")
|
||||
img = ImageTk.PhotoImage(img)
|
||||
show_enhance_button.pack(anchor=tk.CENTER)
|
||||
l1.pack()
|
||||
|
||||
image_label = tk.Label(parent, image=img)
|
||||
image_label.pack()
|
||||
|
||||
# def order_pages():
|
||||
# global image_files
|
||||
# image_files.sort(key=lambda x: int(x.split(".")[0]))
|
||||
|
||||
|
||||
# d'abord faire un dialogue →
|
||||
# order les pages (si pas déjà fait) (0000.jpg, 0001.jpg, 0002.jpg, 0003.jpg, 0004.jpg, 0005.jpg, 0006.jpg, 0007.jpg, 0008.jpg, 0009.jpg, 0010.jpg, etc)
|
||||
# première / dernière page est elle vide ? (si oui del image)
|
||||
# orientation pages paires/impaires correct ?
|
||||
# crop (peut switch entre les pages).
|
||||
|
||||
|
||||
def dialog():
|
||||
dialog_window = tk.Toplevel(parent)
|
||||
dialog_window.title("Dialog")
|
||||
dialog_window.geometry("400x300")
|
||||
|
||||
label = tk.Label(dialog_window, text="Dialog content goes here.")
|
||||
label.pack(pady=20)
|
||||
|
||||
close_button = tk.Button(dialog_window, text="Close", command=dialog_window.destroy)
|
||||
close_button.pack(pady=10)
|
||||
|
||||
|
||||
open_button = tk.Button(
|
||||
parent,
|
||||
anchor="center",
|
||||
cursor="hand2",
|
||||
text="Selectionner le dossier d'images",
|
||||
command=upload_folder,
|
||||
)
|
||||
open_button.pack(pady=10)
|
||||
|
||||
parent.mainloop()
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
Reference in new issue
Block a user