File size: 1,719 Bytes
1743f17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Do stuff to images to prepare them.

"""
from __future__ import annotations

import warnings

from deprecation import deprecated
from PIL import Image


@deprecated(deprecated_in="2021.1", removed_in="", details="use renderWAlphaOffset")
def rasterImageOA(  # pylint:disable=missing-function-docstring

	image: Image.Image, size: tuple[int, int], alpha: float = 1.0, offsets: tuple[int, int] = (0, 0)

) -> Image.Image:
	warnings.warn(
		"Call to deprecated function rasterImageOA.", category=DeprecationWarning, stacklevel=2
	)
	return renderWAlphaOffset(image, size, alpha, offsets)


@deprecated(deprecated_in="2021.1", removed_in="", details="use renderWAlphaOffset")
def rasterImageOffset(  # pylint:disable=missing-function-docstring

	image: Image.Image, size: tuple[int, int], offsets: tuple[int, int] = (0, 0)

) -> Image.Image:
	warnings.warn(
		"Call to deprecated function rasterImageOffset.", category=DeprecationWarning, stacklevel=2
	)
	return renderWAlphaOffset(image, size, 1, offsets)


def renderWAlphaOffset(

	image: Image.Image, size: tuple[int, int], alpha: float = 1.0, offsets: tuple[int, int] = (0, 0)

) -> Image.Image:
	"""Render an image with offset and alpha to a given size.



	Args:

		image (Image.Image): pil image to draw

		size (tuple[int, int]): width, height as a tuple

		alpha (float, optional): alpha transparency. Defaults to 1.0.

		offsets (tuple[int, int], optional): x, y offsets as a tuple.

		Defaults to (0, 0).



	Returns:

		Image.Image: new image

	"""
	imageOffset = Image.new("RGBA", size)
	imageOffset.paste(image.convert("RGBA"), offsets, image.convert("RGBA"))
	return Image.blend(Image.new("RGBA", size), imageOffset, alpha)