Exemplo n.º 1
0
def my_filter(img):
    contrast = ImageEnhance.Contrast(img)
    contrastado = contrast.enhance(1.1)
    brightness = ImageEnhance.Brightness(contrastado)
    brilho = brightness.enhance(1.1)
    saturation = ImageEnhance.Color(brilho)
    saturada = saturation.enhance(1.3)
    arcoiro = Image.open('vinheta.png')
    saturada.paste(arcoiro, (0, 0), arcoiro)
    saturada.show()
    ImagePalette.sepia(saturada).show()
    saturada.save('beijo_vinheta.png')
Exemplo n.º 2
0
def filter_image(filename, filter):
    # strip off prefix from JavaScript File Reader
    image_str = re.sub('^data:image/.+;base64,', '', filename)
    # save decoded Base64 string to bytes object, to simulate file I/O
    in_buffer = BytesIO(base64.b64decode(image_str))
    # Use bytes object to create PIL Image object
    im = Image.open(in_buffer)
    if filter == 'b':
        out = im.filter(ImageFilter.GaussianBlur())
    elif filter == 'g':
        out = im.convert('L')
    elif filter == 's':
        if im.mode != "L":
            im = im.convert("L")
        # Uses make_linear_ramp to create sepia tone palette
        im.putpalette(ImagePalette.sepia("#e5d8ac"))
        out = im
    
    # out.save(UPLOAD_FOLDER + "\\" + outfile + ".png")
    # Use Python Bytes object to simulate file I/O
    out_buffer = BytesIO()
    # Save image into object as a PNG file
    out.save(out_buffer, format="PNG")
    # Read object into string
    image_str = out_buffer.getvalue()
    # Encode bytes object as base64
    out_str = str(b"data:image/png;base64," + base64.b64encode(image_str))
    # strip off Python syntax using regex
    reg = re.sub("^b(?P<quote>['\"])(.*?)(?P=quote)", r'\2', out_str)
    return reg
Exemplo n.º 3
0
def test_imagepalette():
    im = hopper("P")
    im.putpalette(ImagePalette.negative())
    assert_image_equal_tofile(im.convert("RGB"), "Tests/images/palette_negative.png")

    im.putpalette(ImagePalette.random())

    im.putpalette(ImagePalette.sepia())
    assert_image_equal_tofile(im.convert("RGB"), "Tests/images/palette_sepia.png")

    im.putpalette(ImagePalette.wedge())
    assert_image_equal_tofile(im.convert("RGB"), "Tests/images/palette_wedge.png")
Exemplo n.º 4
0
def process_image(src_ps3_path: str, src_ryukishi_path: str, dst_path: str, SMALL_IMAGE_MODE: bool, FOUR_THREE_ASPECT: bool):
	containing_path = str(Path(src_ps3_path).parent)
	containing_path_lower = containing_path.lower()

	ps3_image = Image.open(src_ps3_path)

	ryukishi_image = Image.open(src_ryukishi_path)
	output_image_mode = 'RGB'
	if has_transparency(ryukishi_image):
		output_image_mode = 'RGBA'

	# Convert paletted images to RGB first
	if ryukishi_image.mode in ['P', '1']:
		print(f"WARNING: converting paletted or binary image [{src_ryukishi_path}] to RGB/RGBA")
		ryukishi_image = ryukishi_image.convert(output_image_mode)

	# Check for strange image modes
	if ryukishi_image.mode not in ['RGB', 'RGBA', 'L']:
		raise Exception(f"Unhandled image mode: [{ryukishi_image.mode}]")

	out_noeffect = resize_image(ps3_image, ryukishi_image, SMALL_IMAGE_MODE, FOUR_THREE_ASPECT)

	if 'flashback' in containing_path_lower:
		# TODO: handle transparency when applying flashback effect! Currently converting to greyscale ('L') loses alpha
		out = out_noeffect.convert('L')
		out.putpalette(ImagePalette.sepia())
		out = out.convert(output_image_mode)
		# Adjust the strength of the sepia effect by blending with the original image
		# 0 = no sepia, 1 = full sepia
		out = Image.blend(out_noeffect, out, .7)
	elif 'greyscale' in containing_path_lower:
		# TODO: handle transparency when applying greyscale effect! Currently converting to greyscale ('L') loses alpha
		out = out_noeffect.convert('L')
	elif 'negative' in containing_path_lower:
		out = ImageOps.invert(out_noeffect)
	elif 'blur' in containing_path_lower:
		# This folder uses a zoom motion blur effect which I'm not sure how to implement uisng PIL
		# This folder will have to be done manually
		print(f"WARNING: file {dst_path} should have zoom motion blur applied manually")
		out = out_noeffect
	else:
		out = out_noeffect

	out.save(dst_path)
Exemplo n.º 5
0
 def test_imagepalette(self):
     im = hopper("P")
     im.putpalette(ImagePalette.negative())
     im.putpalette(ImagePalette.random())
     im.putpalette(ImagePalette.sepia())
     im.putpalette(ImagePalette.wedge())
def test_imagepalette():
    im = lena("P")
    assert_no_exception(lambda: im.putpalette(ImagePalette.negative()))
    assert_no_exception(lambda: im.putpalette(ImagePalette.random()))
    assert_no_exception(lambda: im.putpalette(ImagePalette.sepia()))
    assert_no_exception(lambda: im.putpalette(ImagePalette.wedge()))
Exemplo n.º 7
0
 def test_imagepalette(self):
     im = lena("P")
     im.putpalette(ImagePalette.negative())
     im.putpalette(ImagePalette.random())
     im.putpalette(ImagePalette.sepia())
     im.putpalette(ImagePalette.wedge())