Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions reto-08/Palypalillo/image_utils.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions reto-08/Palypalillo/main.py
Original file line number Diff line number Diff line change
@@ -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()
29 changes: 22 additions & 7 deletions reto-09/Palypalillo/image_utils.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
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
if not self.__imageout.parent.exists() or not self.__imageout.parent.is_dir():
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")
Expand All @@ -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)
14 changes: 8 additions & 6 deletions reto-09/Palypalillo/main.py
Original file line number Diff line number Diff line change
@@ -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()
main()
33 changes: 33 additions & 0 deletions reto-10/Palypalillo/instagramfilter.py
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 12 additions & 0 deletions reto-10/Palypalillo/main.py
Original file line number Diff line number Diff line change
@@ -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()
36 changes: 36 additions & 0 deletions reto-11/Palypalillo/imageconvert.py
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 11 additions & 0 deletions reto-11/Palypalillo/main.py
Original file line number Diff line number Diff line change
@@ -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()