Example #1
0
def perspective(image, width, height, skew_x, skew_y, offset_x, offset_y, left,
                top, back_color, opacity, resample, crop, transpose):
    image = imtools.convert_safe_mode(image)
    if transpose == 'NONE':
        transpose = None
    else:
        transpose = getattr(Image, transpose)
        image = image.transpose(imtools.get_reverse_transposition(transpose))
    if opacity != 100 or back_color != '#000000':
        image = image.convert('RGBA')
    if width != 0:
        width = 1 / width
    if height != 0:
        height = 1 / height
    offset_x = offset_x * width
    offset_y = offset_y * height
    skew_x = math.tan(r(skew_x))
    skew_y = math.tan(r(skew_y))
    matrix = (width, skew_x, offset_x, skew_y, height, offset_y, left, top)
    perspectived = image.transform(image.size, Image.PERSPECTIVE, matrix,
                                   resample)
    result = imtools.fill_background_color(
        perspectived, HTMLColorToRGBA(back_color, (255 * opacity) / 100))
    if crop:
        result = imtools.auto_crop(result)
    if not (transpose is None):
        result = result.transpose(transpose)
    return result
Example #2
0
def perspective(image,
        width, height, skew_x, skew_y, offset_x, offset_y,
        left, top, back_color, opacity, resample, crop, transpose):
    image = imtools.convert_safe_mode(image)
    if transpose == 'NONE':
        transpose = None
    else:
        transpose = getattr(Image, transpose)
        image = image.transpose(imtools.get_reverse_transposition(transpose))
    if opacity != 100 or back_color != '#000000':
        image = image.convert('RGBA')
    if width != 0:
        width = 1 / width
    if height != 0:
        height = 1 / height
    offset_x = offset_x * width
    offset_y = offset_y * height
    skew_x = math.tan(r(skew_x))
    skew_y = math.tan(r(skew_y))
    matrix = (width, skew_x, offset_x, skew_y, height, offset_y, left, top)
    perspectived = image.transform(image.size, Image.PERSPECTIVE, matrix,
        resample)
    result = imtools.fill_background_color(perspectived,
        HTMLColorToRGBA(back_color, (255 * opacity) / 100))
    if crop:
        result = imtools.auto_crop(result)
    if not (transpose is None):
        result = result.transpose(transpose)
    return result
Example #3
0
def rotate(image, angle, resample_image, expand=0, amount=100,
        background_color='#000000', background_opacity=100):
    resample_image = getattr(Image, resample_image)
    if background_opacity != 100 or background_color != '#000000':
        image = image.convert('RGBA')
    rotated = image.rotate(angle, resample_image, expand)
    rgba = HTMLColorToRGBA(background_color,
                    255 * background_opacity / 100)
    rotated = imtools.fill_background_color(rotated, rgba)
    if amount < 100:
        rotated = imtools.blend(image, rotated, amount / 100.0, rgba)
    return rotated
Example #4
0
def rotate(image, angle, resample_image, expand=0, amount=100,
        background_color='#000000', background_opacity=100):
    resample_image = getattr(Image, resample_image)
    if background_opacity != 100 or background_color != '#000000':
        image = image.convert('RGBA')
    rotated = image.rotate(angle, resample_image, expand)
    rgba = HTMLColorToRGBA(background_color,
                    255 * background_opacity / 100)
    rotated = imtools.fill_background_color(rotated, rgba)
    if amount < 100:
        rotated = imtools.blend(image, rotated, amount / 100.0, rgba)
    return rotated
Example #5
0
def background(image, fill, mark, color,
        horizontal_offset=None, vertical_offset=None,
        horizontal_justification=None, vertical_justification=None,
        orientation=None, method=None, opacity=100):
    if not has_transparency(image):
        return image
    if image.mode == 'P':
        image = image.convert('RGBA')
    if fill == FILL_CHOICES[0]:
        opacity = (255 * opacity) / 100
        return fill_background_color(image, HTMLColorToRGBA(color,
            opacity))
    elif fill == FILL_CHOICES[1]:
        layer = generate_layer(image.size, mark, method,
                               horizontal_offset, vertical_offset,
                               horizontal_justification,
                               vertical_justification,
                               orientation, opacity)
        paste(layer, image, mask=image)
        return layer
Example #6
0
def background(image,
               fill,
               mark,
               color,
               horizontal_offset=None,
               vertical_offset=None,
               horizontal_justification=None,
               vertical_justification=None,
               orientation=None,
               method=None,
               opacity=100):
    if not has_transparency(image):
        return image
    if image.mode == 'P':
        image = image.convert('RGBA')
    if fill == FILL_CHOICES[0]:
        opacity = (255 * opacity) / 100
        return fill_background_color(image, HTMLColorToRGBA(color, opacity))
    elif fill == FILL_CHOICES[1]:
        layer = generate_layer(image.size, mark, method, horizontal_offset,
                               vertical_offset, horizontal_justification,
                               vertical_justification, orientation, opacity)
        paste(layer, image, mask=image)
        return layer