# Buggy code
def add_decorate(orig, fill_value=None, **decorate):
    """Decorate an image with text and/or logos/images.

    This call adds text/logos in order as given in the input to keep the
    alignment features available in pydecorate.

    An example of the decorate config::

        decorate = {
            'decorate': [
                {'logo': {'logo_path': <path to a logo>, 'height': 143, 'bg': 'white', 'bg_opacity': 255}},
                {'text': {'txt': start_time_txt,
                          'align': {'top_bottom': 'bottom', 'left_right': 'right'},
                          'font': <path to ttf font>,
                          'font_size': 22,
                          'height': 30,
                          'bg': 'black',
                          'bg_opacity': 255,
                          'line': 'white'}}
            ]
        }

    Any numbers of text/logo in any order can be added to the decorate list,
    but the order of the list is kept as described above.

    Note that a feature given in one element, eg. bg (which is the background color)
    will also apply on the next elements  unless a new value is given.

    align is a special keyword telling where in the image to start adding features, top_bottom is either top or bottom
    and left_right is either left or right.
    """
    LOG.info("Decorate image.")

    # Need to create this here to possible keep the alignment
    # when adding text and/or logo with pydecorate
    img_orig = orig.pil_image(fill_value=fill_value)
    from pydecorate import DecoratorAGG

    dc = DecoratorAGG(img_orig)

    # decorate need to be a list to maintain the alignment
    # as ordered in the list
    if "decorate" in decorate:
        for dec in decorate["decorate"]:
            if "logo" in dec:
                add_logo(orig, dc, img_orig, logo=dec["logo"])
            elif "text" in dec:
                add_text(orig, dc, img_orig, text=dec["text"])


# Traceback (ValueError)
[INFO: 2018-10-08 23:46:08 : satpy.writers] Add coastlines and political borders to image.
[DEBUG: 2018-10-08 23:46:08 : satpy.writers] Automagically choose resolution f
[DEBUG: 2018-10-08 23:46:09 : trollimage.xrimage] Interval: left=<xarray.DataArray 'reshape-59920bd5c4344e209a876883f95f2db3' (bands: 1)>
array([0.])
Coordinates:
* bands     (bands) <U1 'L'
quantile  float64 0.005, right=<xarray.DataArray 'reshape-59920bd5c4344e209a876883f95f2db3' (bands: 1)>
array([67.693016])
Coordinates:
* bands     (bands) <U1 'L'
quantile  float64 0.995
Traceback (most recent call last):
File "msg4-ernst_single_channel.py", line 93, in <module>
global_scene.save_dataset(composite,'./MSG4.png', overlay={'coast_dir': '/home/cpeters/software/', 'width':1, 'color':(200, 200, 200)})
File "/home/cpeters/anaconda2/envs/pytroll/lib/python3.6/site-packages/satpy-0+unknown-py3.6.egg/satpy/scene.py", line 1054, in save_dataset
**save_kwargs)
File "/home/cpeters/anaconda2/envs/pytroll/lib/python3.6/site-packages/satpy-0+unknown-py3.6.egg/satpy/writers/__init__.py", line 611, in save_dataset
decorate=decorate, fill_value=fill_value)
File "/home/cpeters/anaconda2/envs/pytroll/lib/python3.6/site-packages/satpy-0+unknown-py3.6.egg/satpy/writers/__init__.py", line 354, in get_enhanced_image
add_overlay(img, dataset.attrs['area'], fill_value=fill_value, **overlay)
File "/home/cpeters/anaconda2/envs/pytroll/lib/python3.6/site-packages/satpy-0+unknown-py3.6.egg/satpy/writers/__init__.py", line 230, in add_overlay
resolution=resolution, width=width, level=level_coast)
File "/home/cpeters/anaconda2/envs/pytroll/lib/python3.6/site-packages/pycoast/cw_agg.py", line 418, in add_coastlines
y_offset=y_offset)
File "/home/cpeters/anaconda2/envs/pytroll/lib/python3.6/site-packages/pycoast/cw_base.py", line 598, in _add_feature
x_offset=x_offset, y_offset=y_offset, **kwargs)
File "/home/cpeters/anaconda2/envs/pytroll/lib/python3.6/site-packages/pycoast/cw_base.py", line 510, in add_shapes
draw = self._get_canvas(image)
File "/home/cpeters/anaconda2/envs/pytroll/lib/python3.6/site-packages/pycoast/cw_agg.py", line 52, in _get_canvas
return aggdraw.Draw(image)
ValueError: bad mode

# Fixed code
def add_decorate(orig, fill_value=None, **decorate):
    """Decorate an image with text and/or logos/images.

    This call adds text/logos in order as given in the input to keep the
    alignment features available in pydecorate.

    An example of the decorate config::

        decorate = {
            'decorate': [
                {'logo': {'logo_path': <path to a logo>, 'height': 143, 'bg': 'white', 'bg_opacity': 255}},
                {'text': {'txt': start_time_txt,
                          'align': {'top_bottom': 'bottom', 'left_right': 'right'},
                          'font': <path to ttf font>,
                          'font_size': 22,
                          'height': 30,
                          'bg': 'black',
                          'bg_opacity': 255,
                          'line': 'white'}}
            ]
        }

    Any numbers of text/logo in any order can be added to the decorate list,
    but the order of the list is kept as described above.

    Note that a feature given in one element, eg. bg (which is the background color)
    will also apply on the next elements  unless a new value is given.

    align is a special keyword telling where in the image to start adding features, top_bottom is either top or bottom
    and left_right is either left or right.
    """
    LOG.info("Decorate image.")

    # Need to create this here to possible keep the alignment
    # when adding text and/or logo with pydecorate
    if hasattr(orig, "convert"):
        # image must be in RGB space to work with pycoast/pydecorate
        orig = orig.convert("RGBA" if orig.mode.endswith("A") else "RGB")
    elif not orig.mode.startswith("RGB"):
        raise RuntimeError(
            "'trollimage' 1.6+ required to support adding "
            "overlays/decorations to non-RGB data."
        )
    img_orig = orig.pil_image(fill_value=fill_value)
    from pydecorate import DecoratorAGG

    dc = DecoratorAGG(img_orig)

    # decorate need to be a list to maintain the alignment
    # as ordered in the list
    img = orig
    if "decorate" in decorate:
        for dec in decorate["decorate"]:
            if "logo" in dec:
                img = add_logo(img, dc, img_orig, logo=dec["logo"])
            elif "text" in dec:
                img = add_text(img, dc, img_orig, text=dec["text"])
    return img