👨💻 Learn How to Code with Private Classes - www.dorscodingschool.com/coachingplans ❓Having a hard time with CS50, FreeCodeCamp or Odin Project? Practice with our exclusive free coding platform: www.codingdors.com/ 🎯 Are You A Coding Expert? Take Our Free Quiz and Find Out - www.dorscodingschool.com/quiz
@sohrabsheghaghi10 ай бұрын
You are a life savior! The best coding teacher. Thanks a lot!
@DavidPinto19792 жыл бұрын
Great content! I was stuck at this one with the Pillow package
@DorsCodingSchool2 жыл бұрын
If you want, we can help you! Telegram Group and Group Coaching: www.dorscodingschool.com/products
@jeffb70726 ай бұрын
Here is mine. I like adding some functions that I reuse in other exercises: import sys from PIL import Image, ImageOps def main(): file_open(sys.argv) main_img = sys.argv[1] output_img = sys.argv[2] # get size of overlay shirt shirt = Image.open("shirt.png") shirt_size = shirt.size # open main_img img_1 = Image.open(main_img) # crop the main_img to the shirt_size cropped_main_img = ImageOps.fit(img_1, shirt_size) # paste the shirt onto the cropped main_img cropped_main_img.paste(shirt, shirt) # save the image with the shirt overlay cropped_main_img.save(output_img) def is_image_file(filename): return filename.strip().lower().endswith((".jpg", ".jpeg", ".png")) def get_extension(filename): return filename.strip().lower().split(".")[-1] def file_open(v): if len(v) < 3: sys.exit("Too few command-line arguments") if len(v) > 3: sys.exit("Too many command-line arguments") if not (is_image_file(v[1]) and is_image_file(v[2])): sys.exit("Invalid input") if get_extension(v[1]) != get_extension(v[2]): sys.exit("Input and output have different extensions") if __name__ == "__main__": main()
@Nikita_Code Жыл бұрын
10:13 i think we can do something like this without creating so many lines of code) elif os.path.splitext(sys.argv[1])[1:] != os.path.splitext(sys.argv[2])[1:]: print("Input and output have different extensions") sys.exit(1)
@8bit-storm60611 ай бұрын
I found this problem being very difficult but thanks to your guidance I finished the program. Muito obg!!!
@luklach2 жыл бұрын
Why the loop for extensions? This will work fine: extensions = ("jpg","jpeg","png",) if len(sys.argv)==3: if sys.argv[1].lower().endswith(extensions) and sys.argv[2].lower().endswith(extensions):
@DorsCodingSchool2 жыл бұрын
I’m not sure if this will work, because you’re if statement should be using “or” instead of “and”. We’d love to help you more. Did you know you can join our Free Discord Group and get help from me and from people around the world that are also learning how to code? dorscodingschool.com/discord
@luklach2 жыл бұрын
@@DorsCodingSchool thats the point, if they both have expected extensions than we proove if they match: extensions = ("jpg","jpeg","png",) if len(sys.argv)==3: if sys.argv[1].lower().endswith(extensions) and sys.argv[2].lower().endswith(extensions): name1, ext1=sys.argv[1].split(".") name2, ext2=sys.argv[2].split(".") if ext2==ext1: filein = sys.argv[1] fileout =sys.argv[2] elif ext2!=ext1: sys.exit("Input and output have different extentions") else: sys.exit("Invalid input")
@VinnieG-9 ай бұрын
I was doing resize() and pasting the shirt differently, cutting the bottom of the muppet pictures, check50 was never going to give me the green light
@slave2truth4freedom2 жыл бұрын
Great Video, this one was a bit confusing as I started reading the documents. The docs still look pretty alien to me.
@DorsCodingSchool2 жыл бұрын
Thank you! I agree, it was complicated to understand ;)
@MohammedSalah2405 Жыл бұрын
python documentation is unfortunatelt miserable.
@manchunyu843 Жыл бұрын
Hello everyone, I am just wondering...instead of resizing the muppet image to fit the shirt, is it possible to do the other way round? (I.E. resizing the shirt to the muppet)
@theresatrevisan10 ай бұрын
You probably could but, but it would be more tricky and the shirt would look bad since its resolution is low compared to the Muppet. You would need to double the shirt size and still do some cropping on the Muppet image. about a 100 pixels off the top and another 100 pixels off the bottom
@luanpires17842 жыл бұрын
import sys import os from PIL import Image, ImageOps if len(sys.argv) < 3: sys.exit("Too few command-line arguments") elif len(sys.argv) > 3: sys.exit("Too many command-line arguments") else: # Getting the extension of the arguments: path_1 = os.path.splitext(sys.argv[1]) path_2 = os.path.splitext(sys.argv[2]) if path_1[1] == "" or path_2[1] == "": sys.exit("Invalid input") elif path_1[1].lower() != path_2[1].lower(): sys.exit("Input and output have different extensions") else: try: shirt = Image.open("shirt.png") with Image.open(sys.argv[1]) as im: photo = ImageOps.fit(im, size=(600, 600)) photo.paste(shirt, shirt) photo.save(sys.argv[2]) except FileNotFoundError: sys.exit("File does not exist")
@DorsCodingSchool2 жыл бұрын
Great job!
@izaanaamir9791 Жыл бұрын
shirt = Image.open("shirt.png") with Image.open(sys.argv[1]) as im: photo = ImageOps.fit(im, size=(600, 600)) photo.paste(shirt, shirt) photo.save(sys.argv[2]) explain this plz!
@luanpires1784 Жыл бұрын
@@izaanaamir9791 first I opened the shirt. Then I opened the first command line argument (the muppet) as an image. ImageOps. fit resizes the muppet image. Then I used .paste to paste the shirt image into the muppet image using the mask parameter (I've explained what this is in another comment or you can just check the pillow docs). Finally, I've saved the changes as the second command line argument.
@AntonioB.Arroyo Жыл бұрын
i'm not sure that code is right, for a few reasons: Run your program with python shirt.py non_existent_image.jpg after1.jpg. Your program should exit using sys.exit and provide an error message: Input does not exist this does not give 'input does not exit' in your code, it gives 'FILE does not exist' Run your program with python shirt.py before1.jpg invalid_format.bmp. Your program should exit using sys.exit and provide an error message: Invalid output Run your program with python shirt.py before1.jpg after1.png. Your program should exit using sys.exit and provide an error message: Input and output have different extensions Both of these give a 'Input and output have different extensions' response, when one should be 'Invalid output' however, i copypasted it to check, and it does pass all CS50 tests, so how come ?
@karabomasilela5465 Жыл бұрын
GOdsent!!!!
@juliaromani8546 Жыл бұрын
Nice video! I am just wondering why dont you try to open the shirt image like you did for the first image?
@theresatrevisan10 ай бұрын
she did Image.open the shirt image, but it is a constant so she did not use a variable and just input the exact name. shirtfile = Image.open("shirt.png")
@aperson72662 жыл бұрын
Thank you, it didn't specify that the image should be 600x600 so I made an image that was 1200x1200 that looked the exact same and it was wrong
@krishnateja507 ай бұрын
Thank you!🎉
@mc-wi8wp2 жыл бұрын
I was only missing the paste option. Dam! Thanks.
@DorsCodingSchool2 жыл бұрын
Glad I could help!
@cruseder2 Жыл бұрын
from PIL import Image, ImageOps import sys def main(): tests() image() def tests(): if len(sys.argv) < 3: sys.exit("Too few command-line arguments") elif len(sys.argv) > 3: sys.exit("Too many command-line arguments") image_types = ["jpg", "jpeg", "png"] arg1 = sys.argv[1] file1, extension1 = arg1.split(".") if extension1 in image_types: pass else: sys.exit("Invalid input") arg2 = sys.argv[2] file2, extension2 = arg2.split(".") if extension2 in image_types: pass else: sys.exit("Invalid output") if extension1 != extension2: sys.exit("Input and output have different extensions") def image(): try: shirt = Image.open("C:\\Users\\MyName\\Downloads\\" + sys.argv[2]) with Image.open("C:\\Users\\Myname\\Pictures\\" + sys.argv[1]) as ik: foto = ImageOps.fit(ik, size=(600,600)) foto.paste(shirt, shirt) foto.show() except FileNotFoundError: print("Invalid input") if __name__ == "__main__": main()
@josepcubedomacian8822 Жыл бұрын
Hello. I'm having trouble with loading the photos in vscode. Any idea on why?
@milithawijenarayana Жыл бұрын
Yh same here it says that there is some webview error, any idea how to do it?
@kwadjoglenn3759 Жыл бұрын
I was having this same problem, but I realized that I had skipped the steps in the "Before You Begin" section, where it tells you how to mkdir and cd. I skipped reading because up until now because most of those steps had been repetitive, but if you scroll to the last of those steps, this assignment requires you to download two wget lines (long lines that I won't type here but are in instructions) as well as an unzip line of code. This allows you access the shirt image and muppet images. These steps must be done before you start writing your program. If you don't do this, you will have problems in other parts of your code. My paste and save functions wouldn't work because "shirt.png" didn't have an image but worked once I downloaded above. Hope this helps.
@santiagootero3580 Жыл бұрын
very usefull explanation, thanks
@andrejg30867 ай бұрын
My antivirus program (Kaspersky) was blocking the loading of images. It was only when I turned it off that the images loaded.
@aramalatrash61474 күн бұрын
OMG i spent an hour on this because I was resizing the shirt to fit the image instead of the other way around, it kept throwing bad transparency mask error, I shouldve solved in in 5min gosh
@czrmartins Жыл бұрын
Perfect video! I didn´t understand why muppet.paste(shirt, shirt) use two times the argument shirt.
@陈枳淳2 жыл бұрын
it returns me "expected exit code 0, not 1' WHY?
@DorsCodingSchool2 жыл бұрын
This is too open. We are only able to help you if we see your code and understand what you're trying to do. Did you know you can join our Discord Group and get help from me and from people around the world that are also learning how to code? dorscodingschool.com/discord
@陈枳淳2 жыл бұрын
@@DorsCodingSchool thanks for your willing to help me, I have already solved it by my self!
@fpron Жыл бұрын
@@陈枳淳 oh great maybe next time clarify WHAT WAS THE FUCKING PROBLEM??
@yagmurfazli4 ай бұрын
@@陈枳淳can you explain how can you solve this? I’m really stuck in it
@陈枳淳4 ай бұрын
@@yagmurfazli yeah, i'll try, it's already 1 yr ago so i'll try to finde my code
@godwinedacheodo29092 жыл бұрын
I keep getting "an error occurred while loading the image" when I open after1.jpg. How do I fix this?
@DorsCodingSchool2 жыл бұрын
Is your image in the same folder as your code? We’d love to help you more. Did you know you can join our Free Discord Group and get help from me and from people around the world that are also learning how to code? dorscodingschool.com/discord
@kwadjoglenn3759 Жыл бұрын
I was having this same problem, but I realized that I had skipped the steps in the "Before You Begin" section, where it tells you how to mkdir and cd. I skipped reading because up until now because most of those steps had been repetitive, but if you scroll to the last of those steps, this assignment requires you to download two wget lines (long lines that I won't type here but are in instructions) as well as an unzip line of code. This allows you access the shirt image and muppet images. These steps must be done before you start writing your program. If you don't do this, you will have problems in other parts of your code. My paste and save functions wouldn't work because "shirt.png" didn't have an image but worked once I downloaded above. Hope this helps.
@notalexbaker4959 Жыл бұрын
I would have overlooked this even though its so obvious lmao, ur comment saved my ass from wasting another hour @@kwadjoglenn3759
@adamkovaac2 жыл бұрын
Hello, can I ask why there is two times "shirtfile" in "muppet.paste(shirtfile, shirtfile)"?
@DorsCodingSchool2 жыл бұрын
I believe you can write only once if you want :)
@luanpires17842 жыл бұрын
The second argument represents the regions (pixels) that will be updated.
@theresatrevisan10 ай бұрын
the first shirtfile is the image to be pasted and the second shirtfile is the alpha channel that will be used as the mask so you don't just get a black square with the shirt. the alpha channel will let it know were paste the shirt and ignore the invisible areas.
@akonthecouch9 ай бұрын
it does let me add a second shirt file @@theresatrevisan
@JenniferA.Moreno8 ай бұрын
Hey why won't 'after1.jpg' appear after running "python shirt.py before1.jpg after1.jpg" ?? Please Help thank you! import sys from PIL import Image def main(): commandline() fileType() invalidOutput() input_file = sys.argv[1] output_file = sys.argv[2] input_extension = input_file.split('.')[-1] output_extension = output_file.split('.')[-1] if input_extension != output_extension: sys.exit("Input and output have different extensions.") try: image = Image.open(input_file) except FileNotFoundError: sys.exit("Input does not exist") # RESIZE SHIRT! shirt = Image.open('shirt.png') size = (200, 150) # New width and height shirt_resized = shirt.resize(size) # OVERLAY SHIRT! image.paste(shirt_resized, (0, 0)) # Save the final image image.save(output_file) def commandline(): if len(sys.argv) < 3: sys.exit("Too few command-line arguments") if len(sys.argv) > 3: sys.exit("Too many command-line arguments") def fileType(): input_file = sys.argv[1] if not input_file.lower().endswith((".jpg", ".jpeg", ".png")): sys.exit("Invalid input file type") def invalidOutput(): output_file = sys.argv[2] if not output_file.lower().endswith((".jpg", ".jpeg", ".png")): sys.exit("Invalid output file type") if __name__ == "__main__": main()
@korydwyer39157 ай бұрын
Having this same issue. Has anyone figured this out yet. I get a prompt saying "input does not exist" and I clearly have it apart of my workspace -_-
@hueshangdangergeld2 жыл бұрын
Hi, I think you won't need to check for capitalization of the extension because in the steps before that you checked what the extensions are in lower case. If they where upper case it would have already exited. Interesting method though I didn't write the program as a couple of functions 👍. I have a question though how does the paste method work? I didn't understand the explanation on problem set. First one is the image to overlay. The second represents a mask indicating which pixel in photo to update. I don't understand the second part can anybody explain it to me?
@DorsCodingSchool2 жыл бұрын
Thank you for your message! The past method will add the second image in front of the t-shirt ;)
@luanpires17842 жыл бұрын
According to .paste documentation: If an image is given as the second argument, the second argument is interpreted as a mask image. If a mask is given, this method updates only the regions indicated by the mask.
@kolawoleomotosho30732 жыл бұрын
Awesome. Just Awesome
@DorsCodingSchool2 жыл бұрын
Thanks!
@marant1642 жыл бұрын
in second line of def check_extension (file) there is a typo instead of .jpeg it is .jepg
@DorsCodingSchool2 жыл бұрын
Thank you
@moumitadhar38902 жыл бұрын
Whenever I type ImageOps it is giving name Error please help
@lucasl68332 жыл бұрын
You haven't import PIL properly
@luanpires17842 жыл бұрын
ImageOps is a module itself, you need to import it as well: from PIL import Image, ImageOps
@armitaparnian75383 ай бұрын
İ'm uploadinh imagr in this workspacr but it doasn'r upload
@ГиоргиЧихладзе11 ай бұрын
Is it normal that I am not able to resolve all these CS50 tasks on my own, and I always need to watch such videos? 😢
@DorsCodingSchool11 ай бұрын
Yes, it's normal
@jayz5320 Жыл бұрын
Below I attached the code I designed. Just to mention I used box to place the shirt in the correct location as my two png had to be resized differently (negative coordinates moves file up and left and positive moves it down and right). Honestly just got here to post a comment so that Giovanna can get more traffic! import sys from PIL import Image,ImageOps ext =[".png", ".jpg", ".jpeg"] if len(sys.argv) < 3: sys.exit("Too few command-line argument") if sys.argv[1].lower().endswith(tuple(ext)) and sys.argv[2].lower().endswith(tuple(ext)) == False: sys.exit("File does not exist") if len(sys.argv) > 3: sys.exit("Too many command-line arguments") else: images = [] image_1 = Image.open(sys.argv[1]) res_image = ImageOps.fit(image_1, (400, 400)) images.append(res_image) image_2 = Image.open(sys.argv[2]) res_image2 = ImageOps.fit(image_2, (500,500)) images.append(res_image2) images[0].paste(images[1], box=(-50,-100), mask=images[1]) images[0].save("after.png")
@DorsCodingSchool Жыл бұрын
Thank you!
@brannstrom122 жыл бұрын
Did someone tell you before that you're awesome?
@DorsCodingSchool2 жыл бұрын
Thank you!!
@Arban1911 ай бұрын
take a shot every time she says blah blah blah
@abdqasrawi8 ай бұрын
why paste has two arguments! what does it mean muppet.past(shirtfile, shirtfile)!!
@mihmd123813 күн бұрын
I was doing muppet.paste(muppet ,shirt) Insted of muppet.paste(shirt, shirt) for ages even chat gbt said nothing is wrong ! This task was a little unclear