23
23
"Installing-Leveler#my-bot-throws-error-on-load-something-related-to-pillow."
24
24
)
25
25
26
+ try :
27
+ from PIL .Image .Resampling import LANCZOS
28
+ except ModuleNotFoundError :
29
+ from PIL .Image import LANCZOS
30
+
26
31
27
32
log = getLogger ("red.fixator10-cogs.leveler" )
28
33
@@ -76,10 +81,10 @@ def _write_unicode(text, init_x, y, font, unicode_font, fill):
76
81
# if char.isalnum() or char in string.punctuation or char in string.whitespace:
77
82
if self .char_in_font (char , check_font ):
78
83
draw .text ((write_pos , y ), "{}" .format (char ), font = font , fill = fill )
79
- write_pos += font . getsize ( char )[ 0 ]
84
+ write_pos += self . _get_character_pixel_width ( font , char )
80
85
else :
81
86
draw .text ((write_pos , y ), "{}" .format (char ), font = unicode_font , fill = fill )
82
- write_pos += unicode_font . getsize ( char )[ 0 ]
87
+ write_pos += self . _get_character_pixel_width ( unicode_font , char )
83
88
check_font .close ()
84
89
85
90
# set canvas
@@ -96,7 +101,7 @@ def _write_unicode(text, init_x, y, font, unicode_font, fill):
96
101
info_section_process = Image .new ("RGBA" , (bg_width , height ), bg_color )
97
102
# puts in background
98
103
temp = bg_image
99
- bg_image = bg_image .resize ((width , height ), Image . ANTIALIAS )
104
+ bg_image = bg_image .resize ((width , height ), LANCZOS )
100
105
temp .close ()
101
106
temp = bg_image
102
107
bg_image = bg_image .crop ((0 , 0 , width , height ))
@@ -151,9 +156,9 @@ def _write_unicode(text, init_x, y, font, unicode_font, fill):
151
156
draw_lvl_circle .ellipse ([0 , 0 , raw_length , raw_length ], fill = (250 , 250 , 250 , 250 ))
152
157
# put on profile circle background
153
158
temp = lvl_circle
154
- lvl_circle = lvl_circle .resize ((lvl_circle_dia , lvl_circle_dia ), Image . ANTIALIAS )
159
+ lvl_circle = lvl_circle .resize ((lvl_circle_dia , lvl_circle_dia ), LANCZOS )
155
160
temp .close ()
156
- lvl_bar_mask = mask .resize ((lvl_circle_dia , lvl_circle_dia ), Image . ANTIALIAS )
161
+ lvl_bar_mask = mask .resize ((lvl_circle_dia , lvl_circle_dia ), LANCZOS )
157
162
process .paste (lvl_circle , (circle_left , circle_top ), lvl_bar_mask )
158
163
lvl_bar_mask .close ()
159
164
@@ -165,13 +170,13 @@ def _write_unicode(text, init_x, y, font, unicode_font, fill):
165
170
# put in profile picture
166
171
output = ImageOps .fit (profile_image , (raw_length , raw_length ), centering = (0.5 , 0.5 ))
167
172
temp = output
168
- output .resize ((profile_size , profile_size ), Image . ANTIALIAS )
173
+ output .resize ((profile_size , profile_size ), LANCZOS )
169
174
temp .close ()
170
175
temp = mask
171
- mask = mask .resize ((profile_size , profile_size ), Image . ANTIALIAS )
176
+ mask = mask .resize ((profile_size , profile_size ), LANCZOS )
172
177
temp .close ()
173
178
temp = profile_image
174
- profile_image = profile_image .resize ((profile_size , profile_size ), Image . ANTIALIAS )
179
+ profile_image = profile_image .resize ((profile_size , profile_size ), LANCZOS )
175
180
temp .close ()
176
181
process .paste (profile_image , (circle_left + border , circle_top + border ), mask )
177
182
@@ -310,7 +315,7 @@ def make_levelup_image(
310
315
311
316
# puts in background
312
317
temp = bg_image
313
- bg_image = bg_image .resize ((width , height ), Image . ANTIALIAS )
318
+ bg_image = bg_image .resize ((width , height ), LANCZOS )
314
319
temp .close ()
315
320
temp = bg_image
316
321
bg_image = bg_image .crop ((0 , 0 , width , height ))
@@ -358,9 +363,9 @@ def make_levelup_image(
358
363
draw_lvl_circle = ImageDraw .Draw (lvl_circle )
359
364
draw_lvl_circle .ellipse ([0 , 0 , raw_length , raw_length ], fill = (250 , 250 , 250 , 180 ))
360
365
temp = lvl_circle
361
- lvl_circle = lvl_circle .resize ((lvl_circle_dia , lvl_circle_dia ), Image . ANTIALIAS )
366
+ lvl_circle = lvl_circle .resize ((lvl_circle_dia , lvl_circle_dia ), LANCZOS )
362
367
temp .close ()
363
- lvl_bar_mask = mask .resize ((lvl_circle_dia , lvl_circle_dia ), Image . ANTIALIAS )
368
+ lvl_bar_mask = mask .resize ((lvl_circle_dia , lvl_circle_dia ), LANCZOS )
364
369
process .paste (lvl_circle , (circle_left , circle_top ), lvl_bar_mask )
365
370
lvl_bar_mask .close ()
366
371
@@ -369,13 +374,13 @@ def make_levelup_image(
369
374
# put in profile picture
370
375
output = ImageOps .fit (profile_image , (raw_length , raw_length ), centering = (0.5 , 0.5 ))
371
376
temp = output
372
- output .resize ((profile_size , profile_size ), Image . ANTIALIAS )
377
+ output .resize ((profile_size , profile_size ), LANCZOS )
373
378
temp .close ()
374
379
temp = mask
375
- mask = mask .resize ((profile_size , profile_size ), Image . ANTIALIAS )
380
+ mask = mask .resize ((profile_size , profile_size ), LANCZOS )
376
381
temp .close ()
377
382
temp = profile_image
378
- profile_image = profile_image .resize ((profile_size , profile_size ), Image . ANTIALIAS )
383
+ profile_image = profile_image .resize ((profile_size , profile_size ), LANCZOS )
379
384
temp .close ()
380
385
process .paste (profile_image , (circle_left + border , circle_top + border ), mask )
381
386
@@ -449,10 +454,10 @@ def _write_unicode(text, init_x, y, font, unicode_font, fill):
449
454
# if char.isalnum() or char in string.punctuation or char in string.whitespace:
450
455
if self .char_in_font (char , check_font ):
451
456
draw .text ((write_pos , y ), "{}" .format (char ), font = font , fill = fill )
452
- write_pos += font . getsize ( char )[ 0 ]
457
+ write_pos += self . _get_character_pixel_width ( font , char )
453
458
else :
454
459
draw .text ((write_pos , y ), "{}" .format (char ), font = unicode_font , fill = fill )
455
- write_pos += unicode_font . getsize ( char )[ 0 ]
460
+ write_pos += self . _get_character_pixel_width ( unicode_font , char )
456
461
check_font .close ()
457
462
458
463
# COLORS
@@ -499,7 +504,7 @@ def _write_unicode(text, init_x, y, font, unicode_font, fill):
499
504
500
505
# puts in background
501
506
temp = bg_image
502
- bg_image = bg_image .resize ((340 , 340 ), Image . ANTIALIAS )
507
+ bg_image = bg_image .resize ((340 , 340 ), LANCZOS )
503
508
temp .close ()
504
509
temp = bg_image
505
510
bg_image = bg_image .crop ((0 , 0 , 340 , 305 ))
@@ -532,9 +537,9 @@ def _write_unicode(text, init_x, y, font, unicode_font, fill):
532
537
)
533
538
# put border
534
539
temp = lvl_circle
535
- lvl_circle = lvl_circle .resize ((lvl_circle_dia , lvl_circle_dia ), Image . ANTIALIAS )
540
+ lvl_circle = lvl_circle .resize ((lvl_circle_dia , lvl_circle_dia ), LANCZOS )
536
541
temp .close ()
537
- lvl_bar_mask = mask .resize ((lvl_circle_dia , lvl_circle_dia ), Image . ANTIALIAS )
542
+ lvl_bar_mask = mask .resize ((lvl_circle_dia , lvl_circle_dia ), LANCZOS )
538
543
process .paste (lvl_circle , (circle_left , circle_top ), lvl_bar_mask )
539
544
lvl_bar_mask .close ()
540
545
@@ -543,10 +548,10 @@ def _write_unicode(text, init_x, y, font, unicode_font, fill):
543
548
border = int (total_gap / 2 )
544
549
profile_size = lvl_circle_dia - total_gap
545
550
temp = mask
546
- mask = mask .resize ((profile_size , profile_size ), Image . ANTIALIAS )
551
+ mask = mask .resize ((profile_size , profile_size ), LANCZOS )
547
552
temp .close ()
548
553
temp = profile_image
549
- profile_image = profile_image .resize ((profile_size , profile_size ), Image . ANTIALIAS )
554
+ profile_image = profile_image .resize ((profile_size , profile_size ), LANCZOS )
550
555
temp .close ()
551
556
process .paste (profile_image , (circle_left + border , circle_top + border ), mask )
552
557
@@ -731,7 +736,7 @@ def _write_unicode(text, init_x, y, font, unicode_font, fill):
731
736
badge_image = badge_image_original .convert ("RGBA" )
732
737
badges_images [num ].close ()
733
738
badge_image_original .close ()
734
- badge_image_resized = badge_image .resize ((raw_length , raw_length ), Image . ANTIALIAS )
739
+ badge_image_resized = badge_image .resize ((raw_length , raw_length ), LANCZOS )
735
740
badge_image .close ()
736
741
737
742
# structured like this because if border = 0, still leaves outline.
@@ -740,9 +745,9 @@ def _write_unicode(text, init_x, y, font, unicode_font, fill):
740
745
# put border on ellipse/circle
741
746
output = ImageOps .fit (square , (raw_length , raw_length ), centering = (0.5 , 0.5 ))
742
747
temp = output
743
- output = output .resize ((size , size ), Image . ANTIALIAS )
748
+ output = output .resize ((size , size ), LANCZOS )
744
749
temp .close ()
745
- outer_mask = mask .resize ((size , size ), Image . ANTIALIAS )
750
+ outer_mask = mask .resize ((size , size ), LANCZOS )
746
751
process .paste (output , coord , outer_mask )
747
752
outer_mask .close ()
748
753
@@ -753,9 +758,9 @@ def _write_unicode(text, init_x, y, font, unicode_font, fill):
753
758
centering = (0.5 , 0.5 ),
754
759
)
755
760
temp = output
756
- output = output .resize ((size - total_gap , size - total_gap ), Image . ANTIALIAS )
761
+ output = output .resize ((size - total_gap , size - total_gap ), LANCZOS )
757
762
temp .close ()
758
- inner_mask = mask .resize ((size - total_gap , size - total_gap ), Image . ANTIALIAS )
763
+ inner_mask = mask .resize ((size - total_gap , size - total_gap ), LANCZOS )
759
764
process .paste (
760
765
output ,
761
766
(coord [0 ] + border_width , coord [1 ] + border_width ),
@@ -771,9 +776,9 @@ def _write_unicode(text, init_x, y, font, unicode_font, fill):
771
776
centering = (0.5 , 0.5 ),
772
777
)
773
778
temp = output
774
- output = output .resize ((size , size ), Image . ANTIALIAS )
779
+ output = output .resize ((size , size ), LANCZOS )
775
780
temp .close ()
776
- outer_mask = mask .resize ((size , size ), Image . ANTIALIAS )
781
+ outer_mask = mask .resize ((size , size ), LANCZOS )
777
782
process .paste (output , coord , outer_mask )
778
783
outer_mask .close ()
779
784
badge_image_resized .close ()
@@ -808,9 +813,9 @@ def _write_unicode(text, init_x, y, font, unicode_font, fill):
808
813
# put border on ellipse/circle
809
814
output = ImageOps .fit (plus_square , (raw_length , raw_length ), centering = (0.5 , 0.5 ))
810
815
temp = output
811
- output = output .resize ((size , size ), Image . ANTIALIAS )
816
+ output = output .resize ((size , size ), LANCZOS )
812
817
temp .close ()
813
- outer_mask = mask .resize ((size , size ), Image . ANTIALIAS )
818
+ outer_mask = mask .resize ((size , size ), LANCZOS )
814
819
process .paste (output , coord , outer_mask )
815
820
outer_mask .close ()
816
821
plus_square .close ()
0 commit comments