code: def _get_image_data(image, colors):
      
      lzw_code_size, coded_bits = _lzw_encode(image, colors)
      coded_bytes = ''.join(
          '{{:0{}b}}'.format(nbits).format(val) for val, nbits in coded_bits)
      coded_bytes = '0' * ((8 - len(coded_bytes)) % 8) + coded_bytes
      coded_data = list(
          reversed([
              int(coded_bytes[8*i:8*(i+1)], 2)
              for i in range(len(coded_bytes) // 8)
          ])
      )
      output = [struct.pack('<B', lzw_code_size)]
      # Must output the data in blocks of length 255
      block_length = min(255, len(coded_data))
      while block_length > 0:
          block = struct.pack(
              '<{}B'.format(block_length + 1),
              block_length,
              *coded_data[:block_length]
          )
          output.append(block)
          coded_data = coded_data[block_length:]
          block_length = min(255, len(coded_data))
      return b''.join(output)
docs: Performs the LZW compression as described by Matthew Flickinger.
  
      This isn't fast, but it works.
      http://www.matthewflickinger.com/lab/whatsinagif/lzw_image_data.asp