def draw_image(self, image, item, source):
        """ Add an image to the image """
        top, left = item['top'], item['left']
        width, height = item['width'], item['height']
        image_file = item['image']

        img = Image.open(source)

        img = self.rotate(img)

        iwidth, iheight = img.size

        wratio = width / iwidth
        hratio = height / iheight

        ratio = min(wratio, hratio)

        img = img.resize((int(iwidth * ratio),
                          int(iheight * ratio)),
                         Image.ANTIALIAS)
        

        # get updated image size
        iwidth, iheight = img.size
        
        # Adjust top, left for actual size of image so centre
        # is in the same place as it would have been
        
        top += (height - iheight) // 2
        left += (width - iwidth) // 2
        
        # now paste the image
        image.paste(img, (left, top))
def draw_image ( self , image , item , source ) : top , left = item [ 'top' ] , item [ 'left' ] width , height = item [ 'width' ] , item [ 'height' ] image_file = item [ 'image' ] img = Image . open ( source ) img = self . rotate ( img ) iwidth , iheight = img . size wratio = width / iwidth hratio = height / iheight ratio = min ( wratio , hratio ) img = img . resize ( ( int ( iwidth * ratio ) , int ( iheight * ratio ) ) , Image . ANTIALIAS ) iwidth , iheight = img . size top += ( height - iheight ) // 2 left += ( width - iwidth ) // 2 image . paste ( img , ( left , top ) )
Add an image to the image