diff --git a/reto-08/Palypalillo/image_utils.py b/reto-08/Palypalillo/image_utils.py index ab7387e..8669c91 100644 --- a/reto-08/Palypalillo/image_utils.py +++ b/reto-08/Palypalillo/image_utils.py @@ -1,7 +1,7 @@ from pathlib import Path from PIL import Image -class ImageUtils(): +class ImageResize(): def __init__(self, imagein, imageout, args=()) -> None: self.__imagein = Path (imagein) @@ -16,7 +16,7 @@ def check(self): return False return True - def resize_image(self): + def execute(self): if "w" in self.__args and "h" in self.__args: if (self.__args['w']/self.__args['h']) != (self.__image.width/self.__image.height): print("La Imagen de Salida no guarda las Proporciones") diff --git a/reto-08/Palypalillo/main.py b/reto-08/Palypalillo/main.py index 4ed99a5..a929f96 100644 --- a/reto-08/Palypalillo/main.py +++ b/reto-08/Palypalillo/main.py @@ -1,12 +1,12 @@ -from image_utils import ImageUtils +from image_utils import ImageResize def main(): - imagein = '/home/paly/Pictures/kitty.jpeg' - imageout = '/home/paly/Pictures/resize_kitty.jpeg' + imagein = '/home/paly/kk/bb.jpg' + imageout = '/home/paly/kk/bbresize.jpg' args = {"w": 200,"h": 150} - imagen = ImageUtils(imagein, imageout, args) + imagen = ImageResize(imagein, imageout, args) if imagen.check(): - imagen.resize_image() + imagen.execute() if __name__ == "__main__": main() \ No newline at end of file diff --git a/reto-09/Palypalillo/image_utils.py b/reto-09/Palypalillo/image_utils.py index 380fa42..90e88cb 100644 --- a/reto-09/Palypalillo/image_utils.py +++ b/reto-09/Palypalillo/image_utils.py @@ -1,14 +1,13 @@ from pathlib import Path from PIL import Image -class ImageUtils(): +class ImageResize(): - def __init__(self, imagein, imageout, args=()) -> None: + def __init__(self, imagein, imageout, args): self.__imagein = Path (imagein) self.__imageout = Path (imageout) self.__args = args - self.__image = Image.open(self.__imagein) - + def check(self): if not self.__imagein.exists() or not self.__imagein.is_file(): return False @@ -16,7 +15,8 @@ def check(self): return False return True - def resize_image(self): + def execute(self): + self.__image = Image.open(self.__imagein) if "w" in self.__args and "h" in self.__args: if (self.__args['w']/self.__args['h']) != (self.__image.width/self.__image.height): print("La Imagen de Salida no guarda las Proporciones") @@ -27,7 +27,22 @@ def resize_image(self): resize_image.save(self.__imageout) else: print("no se ha introducido nuevo tamaƱo") - - def greyscale_image(self): + + +class ImageGrey(): + + def __init__(self, imagein, imageout): + self.__imagein = Path (imagein) + self.__imageout = Path (imageout) + + def check(self): + if not self.__imagein.exists() or not self.__imagein.is_file(): + return False + if not self.__imageout.parent.exists() or not self.__imageout.parent.is_dir(): + return False + return True + + def execute(self): + self.__image = Image.open(self.__imagein) greyscale_image = self.__image.convert("L") greyscale_image.save(self.__imageout) \ No newline at end of file diff --git a/reto-09/Palypalillo/main.py b/reto-09/Palypalillo/main.py index 52e791e..e79dd23 100644 --- a/reto-09/Palypalillo/main.py +++ b/reto-09/Palypalillo/main.py @@ -1,11 +1,13 @@ -from image_utils import ImageUtils +from ast import arg +from image_utils import ImageGrey def main(): - imagein = '/home/paly/Pictures/avatar.jpg' - imageout = '/home/paly/Pictures/grey_avatar.jpg' - imagen = ImageUtils(imagein, imageout) + imagein = '/home/paly/kk/bb.jpg' + imageout = '/home/paly/kk/grey_bb.jpg' + #args = {"h":200, "w":200} + imagen = ImageGrey(imagein, imageout) if imagen.check(): - imagen.greyscale_image() + imagen.execute() if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/reto-10/Palypalillo/instagramfilter.py b/reto-10/Palypalillo/instagramfilter.py new file mode 100644 index 0000000..c3e19f7 --- /dev/null +++ b/reto-10/Palypalillo/instagramfilter.py @@ -0,0 +1,33 @@ +from pathlib import Path +from PIL import Image +import pilgram + +FILTERS = [ + "_1977", "aden", "brannan", "brooklyn", "clarendon", "earlybird", + "gingham", "hudson", "inkwell", "kelvin", "lark", "lofi", "maven", + "mayfair", "moon", "nashville", "perpetua", "reyes", "rise", + "slumber", "stinson", "toaster", "valencia", "walden", "willow", "xpro2"] + +class InstagramImage: + + def __init__(self, filein, fileout, args={}): + self.__filein = Path(filein) + self.__fileout = Path(fileout) + self.__args = args + + def check(self): + if not self.__filein.exists() or not self.__filein.is_file(): + return False + if not self.__fileout.parent.exists() or \ + not self.__fileout.parent.is_dir(): + return False + if "filter" not in self.__args.keys() or \ + self.__args['filter'] not in FILTERS: + return False + return True + + def execute(self): + image = Image.open(self.__filein) + filter_name = self.__args['filter'] + filter = getattr(pilgram, filter_name) + filter(image).save(self.__fileout) \ No newline at end of file diff --git a/reto-10/Palypalillo/main.py b/reto-10/Palypalillo/main.py new file mode 100644 index 0000000..19f0a34 --- /dev/null +++ b/reto-10/Palypalillo/main.py @@ -0,0 +1,12 @@ +from instagramfilter import InstagramImage + +def main(): + filter_name = "valencia" + filein = '/home/paly/kk/bb.jpg' + fileout = f'/home/paly/kk/bb_{filter_name}.jpg' + action = InstagramImage(filein, fileout, {"filter": filter_name}) + if action.check(): + action.execute() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/reto-11/Palypalillo/imageconvert.py b/reto-11/Palypalillo/imageconvert.py new file mode 100644 index 0000000..d468e27 --- /dev/null +++ b/reto-11/Palypalillo/imageconvert.py @@ -0,0 +1,36 @@ +from pathlib import Path +import mimetypes +import re +from PIL import Image + + +ORIGEN = ["image/jpeg", "image/png", "image/x-ms-bmp"] +DESTINO = ["image/jpeg", "image/png", "image/x-ms-bmp", "application/pdf"] + +mimetypes.init() + + +class Convert: + + def __init__(self, filein, fileout): + self.__filein = Path(filein) + self.__fileout = Path(fileout) + + def check(self): + if not self.__filein.exists() or not self.__filein.is_file(): + return False + if not self.__fileout.parent.exists() or \ + not self.__fileout.parent.is_dir(): + return False + mimetype_filein = mimetypes.guess_type(self.__filein)[0] + mimetype_fileout = mimetypes.guess_type(self.__fileout)[0] + if mimetype_filein not in ORIGEN: + return False + if mimetype_fileout not in DESTINO or \ + mimetype_fileout == mimetype_filein: + return False + return True + + def execute(self): + image = Image.open(self.__filein) + image.save(self.__fileout) \ No newline at end of file diff --git a/reto-11/Palypalillo/main.py b/reto-11/Palypalillo/main.py new file mode 100644 index 0000000..9c63112 --- /dev/null +++ b/reto-11/Palypalillo/main.py @@ -0,0 +1,11 @@ +from imageconvert import Convert + +def main(): + filein = '/home/paly/kk/bb.jpg' + fileout = '/home/paly/kk/bb.bmp' + action = Convert(filein, fileout) + if action.check(): + action.execute() + +if __name__ == "__main__": + main() \ No newline at end of file