Skip to content

Instantly share code, notes, and snippets.

@WerctFourth
WerctFourth / crop2-r3.py
Last active March 26, 2026 01:14
Crop empty borders of images and resize using Magic Kernel Sharp 2013 / 6, 7; Produces 16-bit images (12-bit AVIF\HEIF); constant quality using Ssimulacra2 metric
import numpy, numba
import os, pathlib, multiprocessing, subprocess, logging, math, uuid, json, time, argparse
#Border Autocrop 2 R7
#Requires pyVips, Numpy, Numba
#Requires external libVips library
#Can resize images using Magic Kernel 2013 / 6 Sharp 7
#Run the script first time to generate JSON with settings
#resizeMode 1 - Numpy MKS 67, 2 - Numpy Lanczos3, 3 - Numpy MKS2013, 4 - Vips Lanczos3
@WerctFourth
WerctFourth / colorSorter.py
Created July 29, 2025 05:36
Sort images by color (grayscale\rgb), by the need to upscale (below certain resolution), optionally calculate upscale multiplier for NN models and remove original (uses Pillow for image manipulation), 8-bit RGB/16-bit gray max only
from PIL import Image, ImageChops
import pathlib, multiprocessing
inputPath = pathlib.Path("R:/CropResultPng/")
outputPath = pathlib.Path("R:/")
colorPart = "Color"
monoPart = "Monochrome"
upscalePart = "Upscale"
colorThreshold = 20
@WerctFourth
WerctFourth / crop2.py
Last active February 23, 2025 09:44
Crop empty borders of pictures\manga and resize using Magic Kernel Sharp 6, 7; Produces 16-bit images (12-bit AVIFs)
import numpy, numba
import os, pathlib, multiprocessing, subprocess, logging, math, uuid, json, time, argparse
#Border Autocrop 2 R2
#Requires pyVips, Numpy, Numba
#Requires external libVips library
#Can resize images using Magic Kernel 6 Sharp 7
#Run the script first time to generate JSON with settings
#resizeMode 1 - Numpy MKS67, 2 - Numpy Lanczos3, 3 - Vips Lanczos3
@WerctFourth
WerctFourth / crop.py
Last active April 19, 2024 14:28
Crop monochrome/solid color borders from pictures or manga
from PIL import Image
import os, pathlib, multiprocessing, subprocess, logging, numpy
#Border auto-crop R3-rel
#Crops solid-color border from all sides of a picture (PNG/JPG), supports color pictures, outputs PNG and optionally converts to AVIF
#Somewhat resistant to noise and JPEG artifacts
#Multiprocessed
#Auto-resizes pictures to fit a certain screen by width
#Tested on Python 3.12.2, Pillow 10.3.0 and NumPy 1.26.4