def resize_dim(img, new_width):
    """ Calculate new dimensions while preserving the image's aspect ratio """
    old_width, old_height = img.size
    aspect_ratio = float(old_height) / float(old_width)
    new_height = int(aspect_ratio * new_width)
    return new_width, new_height