Comments (1)
something like this
code from Tabnine AI
def resize_image(resize_mode, im, width, height, upscaler_name=None, crop_anchor=(0.5, 0.5)):
"""
Resizes an image with the specified resize_mode, width, height, and crop_anchor.
Args:
resize_mode: The mode to use when resizing the image.
0: Resize the image to the specified width and height.
1: Resize the image to fill the specified width and height, maintaining the aspect ratio, and then center the image within the dimensions, cropping the excess.
2: Resize the image to fit within the specified width and height, maintaining the aspect ratio, and then center the image within the dimensions, filling empty with data from image.
im: The image to resize.
width: The width to resize the image to.
height: The height to resize the image to.
upscaler_name: The name of the upscaler to use. If not provided, defaults to opts.upscaler_for_img2img.
crop_anchor: The point from which the image should be cropped. The values should be between 0 and 1, representing the x and y coordinates of the anchor point. The default value is (0.5, 0.5), which represents the center of the image.
"""
#... (existing code)
elif resize_mode == 1:
ratio = width / height
src_ratio = im.width / im.height
src_w = width if ratio > src_ratio else im.width * height // im.height
src_h = height if ratio <= src_ratio else im.height * width // im.width
resized = resize(im, src_w, src_h)
res = Image.new("RGB", (width, height))
# Calculate the coordinates of the crop box based on the crop_anchor
x_offset = int(crop_anchor[0] * (resized.width - src_w))
y_offset = int(crop_anchor[1] * (resized.height - src_h))
res.paste(resized, box=(width // 2 - src_w // 2 - x_offset, height // 2 - src_h // 2 - y_offset))
#... (existing code)
from stable-diffusion-webui.
Related Issues (20)
- [Bug]: SD3 Lora Trained with OneTrainer has ValueError in networks.py - but Working fine with ComfyUI HOT 2
- adetailer mediapipe (requirements:protobuf==4.25.4) in webui v1.10.1 bug. But webui v1.10.1 requirements:protobuf==3.20.0。Causes webui v1.10.1 crash, disable the plugin to use **webui v1.10.1**。 Can I set the adetailer and mediapipe runtime environment(protobuf==3.20.0)? HOT 1
- [Bug]: Adding "txt2img" to "Hidden UI tabs" makes img2img no longer function HOT 2
- [Feature Request]: Add UNET and CLIP temperature HOT 1
- [Bug]:error LDSR upscale HOT 2
- [Bug]: Loading the stable diffusion model failed HOT 2
- [Bug]: Automatic1111 fails to load weights
- [Bug]: Reactor Error - SD 1.5, Colab Pro
- [Bug]: Too many visits to /run/predict HOT 1
- [Feature Request]: ERROR: Could not install packages due to an OSError: [Errno 28] : by pass proposition
- [Bug]: RuntimeError: CUDA Setup failed despite GPU being available. Please run the following command to get more information: python -m bitsandbytes Inspect the output of the command and see if you can locate CUDA libraries. You might need to add them to your LD_LIBRARY_PATH. If you suspect a bug, please take the information from python -m bitsandbytes and open an issue at: https://github.com/TimDettmers/bitsandbytes/issues
- [Bug]: AttributeError: 'str' object has no attribute '__traceback__'
- [Bug]: SD3 model is not loading
- [Bug]: Connection refused behind proxy HOT 5
- [Bug]: SwinIR v2 support regressed?
- [Bug]: ERROR: No matching distribution found for torch==2.1.2 HOT 1
- [Bug]: image generation will fail or will succeed with some tags but not with others. I could not found a consistent rule on what tags it does this HOT 1
- [Bug]: Cannot use CosXL_edit model
- json.decoder.JSONDecodeError: Expecting value: line 14177 column 36 (char 897167) HOT 2
- [Bug]: extensions 與 extranetworks 總是無法載入列表
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stable-diffusion-webui.