403Webshell
Server IP : www.new.bangkokfinder.com  /  Your IP : 162.158.106.112
Web Server : nginx/1.20.1
System : Linux new 4.15.0-159-generic #167-Ubuntu SMP Tue Sep 21 08:55:05 UTC 2021 x86_64
User : bangkokfinder ( 1000)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/bangkokf/public_html/wp-content/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/bangkokf/public_html/wp-content/convert.py
import os
from pathlib import Path
from PIL import Image
from tqdm import tqdm
from concurrent.futures import ThreadPoolExecutor

# Пути к директориям исходных и целевых файлов
source_dir = Path("uploads/WPL/ALL_IMAGE_FOLDERS/")
target_dir = Path("uploads-webp/WPL/ALL_IMAGE_FOLDERS/")
quality = 70  # качество WebP

# Функция для конвертации изображений в одной директории
def convert_directory(folder):
    images = list(folder.rglob("*.jpg")) + list(folder.rglob("*.jpeg"))
    folder_name = folder.relative_to(source_dir)
    
    # Отображаем прогресс для текущей директории
    with tqdm(total=len(images), desc=f"Конвертация {folder_name}", unit="файл") as pbar:
        for img_path in images:
            # Задаем путь для сохранения нового изображения
            relative_path = img_path.relative_to(source_dir)
            new_path = target_dir / relative_path.with_suffix(".webp")
            new_path.parent.mkdir(parents=True, exist_ok=True)

            try:
                # Конвертируем изображение
                with Image.open(img_path) as img:
                    img.save(new_path, "WEBP", quality=quality)
            except (UnidentifiedImageError, OSError) as e:
                print(f"Ошибка при конвертации {img_path}: {e}")
                # Пропускаем текущее изображение и продолжаем обработку
            finally:
                pbar.update(1)

# Основная функция для запуска многопоточного выполнения
def convert_images_to_webp():
    # Получаем первую вложенность директорий
    folders = [f for f in source_dir.iterdir() if f.is_dir()]
    
    # Запускаем пул потоков
    with ThreadPoolExecutor(max_workers=2) as executor:
        for i, _ in enumerate(executor.map(convert_directory, folders), start=1):
            print(f"Обработана директория {i}/{len(folders)}")

if __name__ == "__main__":
    convert_images_to_webp()

Youez - 2016 - github.com/yon3zu
LinuXploit