Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken image downscale TypeError #7945

Merged
merged 1 commit into from
Feb 20, 2023

Conversation

w-e-w
Copy link
Collaborator

@w-e-w w-e-w commented Feb 20, 2023

Fx broken image downscale caused by reword settings for 4chan export, remove unneded try/excepts, add try/except for actually saving JPG which also remove the float to int casting of opts.target_side_length
as resize size can only be integer tuple this raises an error causing the downscale to fail

Error completing request
Arguments: (0, <PIL.Image.Image image mode=RGB size=768x1024 at 0x20703F08250>, None, '', '', True, 0, 4, 512, 512, True, 'R-ESRGAN 4x+ Anime6B', 'None', 0, 0, 0, 0) {}
Traceback (most recent call last):
  File "B:\Documents\GitHub\stable-diffusion-webui\modules\call_queue.py", line 56, in f
    res = list(func(*args, **kwargs))
  File "B:\Documents\GitHub\stable-diffusion-webui\modules\call_queue.py", line 37, in f
    res = func(*args, **kwargs)
  File "B:\Documents\GitHub\stable-diffusion-webui\modules\postprocessing.py", line 70, in run_postprocessing
    images.save_image(pp.image, path=outpath, basename=basename, seed=None, prompt=None, extension=opts.samples_format, info=infotext, short_filename=True, no_prompt=True, grid=False, pnginfo_section_name="extras", existing_info=existing_pnginfo, forced_filename=None)
  File "B:\Documents\GitHub\stable-diffusion-webui\modules\images.py", line 587, in save_image
    image = image.resize((image.width * opts.target_side_length // image.height, opts.target_side_length), LANCZOS)
  File "B:\Documents\GitHub\stable-diffusion-webui\venv\lib\site-packages\PIL\Image.py", line 2192, in resize
    return self._new(self.im.resize(size, resample, box))
TypeError: 'float' object cannot be interpreted as an integer

This PR fixes the issue
yes I could just typed casted as I did before
but since I'm bored I used round() for more accurate approximation

note: the round() functions will returns int type
Return number rounded to ndigits precision after the decimal point. If ndigits is omitted or is None, it returns the nearest integer to its input.

why also use round() on opts.target_side_length and not int()?
for those thick headed people that decides to use a non integer value

@w-e-w w-e-w requested a review from AUTOMATIC1111 as a code owner February 20, 2023 08:59
@w-e-w w-e-w changed the title Fix image downscale TypeError Fix broken image downscale TypeError Feb 20, 2023
@AUTOMATIC1111 AUTOMATIC1111 merged commit 0cc0ee1 into AUTOMATIC1111:master Feb 20, 2023
@andyxr
Copy link

andyxr commented Feb 22, 2023

"thick headed people"?

@2blackbar 2blackbar mentioned this pull request Mar 2, 2023
1 task
@w-e-w w-e-w deleted the fix-image-downscale branch August 10, 2023 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants