code: def web2hex(web, force_long=False):
      """Converts WEB representation to HEX
  
      :param rgb: web string representation (human readable if possible)
      :rtype: 3 hex char or 6 hex char string representation
  
      WEB representation uses X11 rgb.txt to define conversion
      between RGB and english color names.
  
      Usage
      =====
  
      >>> from colour import web2hex
  
      >>> web2hex('red')
      '#f00'
  
      >>> web2hex('#aaa')
      '#aaa'
  
      >>> web2hex('#foo')  # doctest: +ELLIPSIS
      Traceback (most recent call last):
      ...
      AttributeError: '#foo' is not in web format. Need 3 or 6 hex digit.
  
      >>> web2hex('#aaa', force_long=True)
      '#aaaaaa'
  
      >>> web2hex('#aaaaaa')
      '#aaaaaa'
  
      >>> web2hex('#aaaa')  # doctest: +ELLIPSIS
      Traceback (most recent call last):
      ...
      AttributeError: '#aaaa' is not in web format. Need 3 or 6 hex digit.
  
      >>> web2hex('pinky')  # doctest: +ELLIPSIS
      Traceback (most recent call last):
      ...
      ValueError: 'pinky' is not a recognized color.
  
      And color names are case insensitive:
  
      >>> Color('RED')
      <Color red>
  
      """
      if web.startswith("#"):
          if LONG_HEX_COLOR.match(web) or (
              not force_long and SHORT_HEX_COLOR.match(web)
          ):
              return web.lower()
          elif SHORT_HEX_COLOR.match(web) and force_long:
              return "#" + "".join([("%s" % (t,)) * 2 for t in web[1:]])
          raise AttributeError(
              "%r is not in web format. Need 3 or 6 hex digit." % web
          )
  
      web = web.lower()
      if web not in COLOR_NAME_TO_RGB:
          raise ValueError("%r is not a recognized color." % web)
  
      # convert dec to hex:
  
      return rgb2hex(
          [float(int(v)) / 255 for v in COLOR_NAME_TO_RGB[web]],
          force_long,
      )
  
imports: from __future__ import with_statement, print_function
  import hashlib
  import re
  import sys
label_desc: Use image node_id 7 for calling a global function with example usage: web2hex(web, force_long) and returns: rgb2hex, web, unknown