code: def draw_pattern_fill(image, psd, setting, blend=True):
      
      from PIL import Image
      pattern_id = setting[b'Ptrn'][b'Idnt'].value.rstrip('\x00')
      pattern = psd._get_pattern(pattern_id)
      if not pattern:
          logger.error('Pattern not found: %s' % (pattern_id))
          return None
      panel = convert_pattern_to_pil(pattern, psd._record.header.version)
  
      scale = setting.get(b'Scl ', 100) / 100.
      if scale != 1.:
          panel = panel.resize((
              int(panel.width * scale),
              int(panel.height * scale)
          ))
  
      opacity = int(setting.get(b'Opct', 100) / 100. * 255)
      if opacity != 255:
          panel.putalpha(opacity)
  
      pattern_image = Image.new(image.mode, image.size)
      mask = image.getchannel('A') if blend else Image.new('L', image.size, 255)
  
      for left in range(0, pattern_image.width, panel.width):
          for top in range(0, pattern_image.height, panel.height):
              panel_mask = mask.crop(
                  (left, top, left + panel.width, top + panel.height)
              )
              pattern_image.paste(panel, (left, top), panel_mask)
  
      if blend:
          image.paste(_blend(image, pattern_image, (0, 0)))
      else:
          image.paste(pattern_image)
docs: Draw pattern fill on the image.
  
      :param image: Image to be filled.
      :param psd: :py:class:`PSDImage`.
      :param setting: Descriptor containing pattern fill.
      :param blend: Blend the fill or ignore. Effects blend.