def _image_size(image_config, type_, target_size):
        """Find the closest available size for specified image type.

        Arguments:
          image_config (:py:class:`dict`): The image config data.
          type_ (:py:class:`str`): The type of image to create a URL
            for, (``'poster'`` or ``'profile'``).
          target_size (:py:class:`int`): The size of image to aim for (used
            as either width or height).

        """
        return min(
            image_config['{}_sizes'.format(type_)],
            key=lambda size: (abs(target_size - int(size[1:]))
                              if size.startswith('w') or size.startswith('h')
                              else 999),
        )