@@ -686,7 +686,7 @@ def adjust_gamma(img, gamma, gain=1):
686686 return img
687687
688688
689- def rotate (img , angle , resample = False , expand = False , center = None ):
689+ def rotate (img , angle , resample = False , expand = False , center = None , fill = 0 ):
690690 """Rotate the image by angle.
691691
692692
@@ -703,6 +703,8 @@ def rotate(img, angle, resample=False, expand=False, center=None):
703703 center (2-tuple, optional): Optional center of rotation.
704704 Origin is the upper left corner.
705705 Default is the center of the image.
706+ fill (3-tuple or int): RGB pixel fill value for area outside the rotated image.
707+ If int, it is used for all channels respectively.
706708
707709 .. _filters: https://pillow.readthedocs.io/en/latest/handbook/concepts.html#filters
708710
@@ -711,7 +713,10 @@ def rotate(img, angle, resample=False, expand=False, center=None):
711713 if not _is_pil_image (img ):
712714 raise TypeError ('img should be PIL Image. Got {}' .format (type (img )))
713715
714- return img .rotate (angle , resample , expand , center )
716+ if isinstance (fill , int ):
717+ fill = tuple ([fill ] * 3 )
718+
719+ return img .rotate (angle , resample , expand , center , fillcolor = fill )
715720
716721
717722def _get_inverse_affine_matrix (center , angle , translate , scale , shear ):
0 commit comments