def scale_dimensions(width, height, longest_side):
    """ Calculates image ratio given a longest side
    returns a tupple with ajusted width, height

    @param width:  integer, the current width of the image
    @param height:  integer, the current height of the image
    @param longest_side:   the longest side of the resized image
    @return: resized width, height

    >>> scale_dimensions(680, 480, 340)
    340, 240
    >>> scale_dimensions(480, 680, 340)
    240, 340

    """
    if width > height:
        if width > longest_side:
            ratio = longest_side * 1. / width
            return int(width * ratio), int(height * ratio)
    elif height > longest_side:
        ratio = longest_side * 1. / height
        return int(width * ratio), int(height * ratio)
    return width, height