Resize images based on Pixel amount to optimize max size to vram usage and to keep the original pics uncropped #7367
spechok
started this conversation in
Show and tell
Replies: 1 comment
-
another option that comes in with darkening transparent PNG pixels to full black(0,0,0,255) import os def resize_image(img_path, max_pixels):
Maximum number of pixelsmax_pixels = 600000 Folder namefolder_name = r"E:\stable_diffusion\1" Loop through all files in the folderfor filename in os.listdir(folder_name):
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
first ever something something
lets get started:
import os
from PIL import Image
import math
def resize_image(img_path, max_pixels):
# Open the image
Maximum number of pixels
max_pixels = 600000
#you're gonna need to know what is your max pixel amount is, for me it is 6gbvram - so 768*768 =~590,000 from tests i could use up to #~600,000 pixels
Folder name
folder_name = r"E:\stable_diffusion\1"
Loop through all files in the folder
for filename in os.listdir(folder_name):
# Get the file path
file_path = os.path.join(folder_name, filename)
and this is it...
this code basically will take your images and resize them with the same Vertical to Horizontal ratio but to the right resolution
dunno how to implement it into the gradio sadly
anyway, hope ya like it
Beta Was this translation helpful? Give feedback.
All reactions