You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Moreover, the line char_width, char_height = font.getsize(sample_character) generate a warning: DeprecationWarning: getsize is deprecated and will be removed in Pillow 10 (2023-07-01). Use getbbox or getlength instead.
So on utils.py, all lines similar to char_width, char_height = font.getsize("◊") (with various values for ◊) needs to be replaced by:
So, by rearranging order of some calculus (because the calculus of cell_height needs to known the value of char_height / char_width), I suggest this correction in the code of img2img.py (extract of the code for the main function):
So, with the modified code, python3 img2img.py --num_cols 100 --language general --mode complex --background white --output data/NewOutput.png gives:
The dimension of this corrected image is 1200×648, and it's aspect ratio is 1200/648=1.85, which is near the 1.81 aspect ratio of the original image.
I will show a more visible difference, by scaling the outputted image, so it's width is the same as the inputed image, and displaying it in a graphic manipulation software, with a transparent backgroung over the inputed image:
Before the correction:
After the correction:
The text was updated successfully, but these errors were encountered:
quark67
changed the title
Incorrect aspect ratio in output of img2img.py (and similars: img2img_color.py, video2video.py and video2video_color.py)
Incorrect aspect ratio in output of img2img.py (and similars: img2img_color.py, video2video.py and video2video_color.py)
Feb 21, 2024
From the demo image (dimension: 976×538, aspect ratio = 976/538 = 1.81):
python3 img2img.py --num_cols 100 --language general --mode complex --background white --output data/output.png
gives:which is a picture of dimension 1200×515 (aspect ratio = 1200/515 = 2.33, which is very different from 1.81).
The reason is this line of code:
cell_height = scale * cell_width
(in line 36 ofimg2img.py
).The factor
cell_height / cell_width
needs to be the same as the factorchar_height / char_width
, so the previous code becomes:cell_height = (char_height / char_width) * cell_width
.Moreover, the line
char_width, char_height = font.getsize(sample_character)
generate a warning:DeprecationWarning: getsize is deprecated and will be removed in Pillow 10 (2023-07-01). Use getbbox or getlength instead.
So on
utils.py
, all lines similar tochar_width, char_height = font.getsize("◊")
(with various values for ◊) needs to be replaced by:(caution: there is no missing
char_bbox[1]
in the previous code. And strangely "bottom" really gives the height. See this: python-pillow/Pillow#7802).This correction must also be made in line 44 of
img2img.py
: remplacechar_width, char_height = font.getsize(sample_character)
withSo, by rearranging order of some calculus (because the calculus of
cell_height
needs to known the value ofchar_height / char_width
), I suggest this correction in the code ofimg2img.py
(extract of the code for themain
function):For comparison, the old code for the same portion was:
So, with the modified code,
python3 img2img.py --num_cols 100 --language general --mode complex --background white --output data/NewOutput.png
gives:The dimension of this corrected image is 1200×648, and it's aspect ratio is 1200/648=1.85, which is near the 1.81 aspect ratio of the original image.
I will show a more visible difference, by scaling the outputted image, so it's width is the same as the inputed image, and displaying it in a graphic manipulation software, with a transparent backgroung over the inputed image:
Before the correction:
After the correction:
The text was updated successfully, but these errors were encountered: