def saturation(x, value): ''' Extends colors app saturation filter with relative changes using "+" and "-". Example usage: {{ color|saturation:"+5" }} {{ color|saturation:"-5" }} {{ color|saturation:"50" }} ''' x = expand_hex(x) h, s, v = hex_to_hsv(x, False) if len(x) == 6 else x # technically, saturation cannot increase _relatively_ from 0 # i.e. gray remains gray regardless of saturation increase if s > 0: if str(value).startswith('+'): value = int(s) + int(value[1:]) if value > 100: value = 100 if str(value).startswith('-'): value = int(s) - int(value[1:]) if value < 0: value = 0 else: value = 0 return colors_saturation(x, value)
def hue(x, value): ''' Extends colors app hue filter with relative changes using "+" and "-". Example usage: {{ color|hue:"+180" }} {{ color|hue:"-180" }} {{ color|hue:"180" }} ''' x = expand_hex(x) h, s, v = hex_to_hsv(x, False) if len(x) == 6 else x if str(value).startswith('+'): value = int(h) + int(value[1:]) if str(value).startswith('-'): value = int(h) - int(value[1:]) # compensate for values falling outside the range 0-360 if int(value) > 360 or int(value) < 0: value = int(value) % 360 return colors_hue(x, value)
def lightness(x, value): ''' Extends colors app lightness filter with relative changes using "+" and "-". Example usage: {{ color|lightness:"+5" }} {{ color|lightness:"-5" }} {{ color|lightness:"50" }} ''' x = expand_hex(x) h, s, v = hex_to_hsv(x, False) if len(x) == 6 else x if str(value).startswith('+'): value = int(v) + int(value[1:]) if value > 100: value = 100 if str(value).startswith('-'): value = int(v) - int(value[1:]) if value < 0: value = 0 return colors_lightness(x, value)