Example #1
0
def pot_square_resize(img, maximum=None):
    """Resize image to power of two square

    :type img: QImage
    :param img: input image
    :type maximum: int or None
    :param maximum: maximum size (must be 2**n)
    :return: resized image
    """
    resized = pot_resize(img, maximum=maximum)
    w, h = resized.width(), resized.height()
    base = max(w, h)
    #pad = base - min(w, h)
    new_img = QImage(base, base, img.format())
    new_img.fill(QColor(0, 0, 0))
    painter = QPainter(new_img)
    painter.drawImage(0, 0, resized)
    return new_img, w / base, h / base