Skip to content

Instantly share code, notes, and snippets.

@adambom
Last active September 5, 2018 21:31
Show Gist options
  • Save adambom/a995392ae009041a38800e326ce1b27a to your computer and use it in GitHub Desktop.
Save adambom/a995392ae009041a38800e326ce1b27a to your computer and use it in GitHub Desktop.
class ImageProcessor:
def __init__(
self,
image: Image,
image_resizer: ImageResizer,
image_grayscale_converter: ImageGrayscaleConverter,
image_rotator: ImageRotator,
):
self._image = image
self._resizer = image_resizer
self._grayscale_converter = image_grayscale_converter
self._rotator = image_rotator
def process(self, width=None, height=None, color=True, rotation=0):
self._resizer.resize(image, width, height)
self._grayscale_converter.convert(image, color)
self._rotator.rotate(image, rotation)
class ImageResizer:
pass
class ImageGrayscaleConverter:
pass
class ImageRotator:
pass
class ImageProcessor:
def __init__(self, image):
self._image = image
def process(self, width=None, height=None, color=True, rotation=0):
self._resize(width, height)
if color is True:
self._to_grayscale()
self._rotate(rotation)
def _resize(self, width, height):
for h_pixel in self._image:
for v_pixel in self._image:
# I clearly have no idea how to resize an image
self._image += (h_pixel + v_pixel) / (width * height)
def _to_grayscale(self):
for h_pixel in self._image:
for v_pixel in self._image:
pixel = self._image[h_pixel, v_pixel]
# I clearly have no idea how to convert an image to grayscale
self._image[h_pixel, v_pixel] = rgba(0, 0, 0, pixel.get_alpha())
def _rotate(self, degrees):
if degrees == 0:
return
for h_pixel in self._image:
for v_pixel in self._image:
pixel = self._image[h_pixel, v_pixel]
# I clearly have no idea how to rotate an image
self._image[h_pixel * degrees, -1 * v_pixel / degrees] = pixel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment