Image Manipulation in Python [ A complete guide to Pillow ]

Поділитися
Вставка
  • Опубліковано 29 чер 2024
  • Basically everything you need to know about image manipulation in Python with Pillow [PIL]. By the end of the video you should be comfortable manipulating images in just about every way.
    If you want to support me: / clearcode
    (You also get lots of perks)
    Social stuff:
    Twitter - / clear_coder
    Discord - / discord
    Timestamps
    00:00:00 - Intro
    00:01:22 - Basic image operations
    00:09:10 - Basic image manipulation
    00:22:45 - Filters and image enhancements
    00:38:19 - Colors in Pillow [ Deepdive ]
    01:11:22 - Image operations [ ImageOps ]
    01:25:01 - Deformer
    1:41:14 - Drawing shapes
    1:54:35 - Combining images + ImageChops
    02:09:46 - Masks
    Github
    github.com/clear-code-project...
    Pastebin
    1 Basics - pastebin.com/f24F9w7x
    2 Basic_manipulation - pastebin.com/F2ht4D1S
    3 Enhance - pastebin.com/mRaBRzNt
    5 Filters - pastebin.com/xEw9sxBM
    6 Colors - pastebin.com/TLqzCSSB
    7 ImageOps - pastebin.com/g0HgW8zG
    8 Deformer - pastebin.com/zRE250cB
    9 - Shapes - pastebin.com/bMYxFfaA
    9 - pastebin.com/TyFVQ2LA

КОМЕНТАРІ • 72

  • @sozno4222
    @sozno4222 5 місяців тому +2

    Christian, you are a fantastic instructor. I bought your course on tkinter and I can't get over how clear and concise you are in your instruction. I look forward to digging into more of your courses. Thanks for the hard work you put into these courses.

  • @thinkmediadeeper
    @thinkmediadeeper Рік тому +5

    the first tutorial so simple and clear on python, thank you so much, I literally struggled several weeks before to find smth like this

  • @djohnworthy1040
    @djohnworthy1040 Рік тому +3

    Hey Clear Code, thanks a lot for such great content. Today I discovered your channel. The explanation and presentation are so clean.

  • @ahmedsaliem7041
    @ahmedsaliem7041 10 місяців тому

    I'm so grateful to see this course. I really appreciate your response 🙏.

  • @c0nsumption
    @c0nsumption Рік тому +10

    This is the greatest overview of a module/library I have ever seen. I have all my files saved from this and constantly just go back to copy, paste, and edit.
    Thank you, you are incredible.

  • @YassFreeks
    @YassFreeks 2 роки тому +2

    Thank you Sir, let's add this to my watch list 🙃

  • @alisaleh1900
    @alisaleh1900 Рік тому

    Highly appreciated you have saved my time

  • @davipereira2533
    @davipereira2533 Місяць тому

    Excellent video! It helped me a lot, thank you very much! 🥰

  • @serbrawl7981
    @serbrawl7981 2 роки тому

    thank you, the thumbnail is very catchy

  • @IT-tx8sg
    @IT-tx8sg Рік тому

    Thank you for making this video

  • @tortokaeva
    @tortokaeva Рік тому

    Thanks, very clear!!!

  • @on2k23nm
    @on2k23nm 5 місяців тому

    Nice & informaative video

  • @sksahil4374
    @sksahil4374 Рік тому

    Great Tutorial

  • @DarkAcademyUniversity
    @DarkAcademyUniversity 3 місяці тому

    An awesome channel!

  • @su1nta
    @su1nta Рік тому +4

    Update: In image flip/transpose, *Image.Transpose.* isn't used anymore. Instead we can use *Image.* where the can be TRANSPOSE, FLIP_LEFT_RIGHT etc.

  • @ArjunMehrotra
    @ArjunMehrotra 2 роки тому

    Thank you!

  • @Abdullah_N1987
    @Abdullah_N1987 Рік тому

    Question. Is there some kind of what you see is what you get tool to help with complicated manipulations? especially ones that involve multiple layers and text? doing it by hand takes a lot of trial and error

  • @philtoa334
    @philtoa334 2 роки тому

    Nice.

  • @johnkoepke7987
    @johnkoepke7987 3 місяці тому

    Thanks!

    • @ClearCode
      @ClearCode  3 місяці тому

      thank you so much! :)

  • @allenbennett8735
    @allenbennett8735 Рік тому

    I just found your channel this morning, and it's the first one that has taught me about images, so I thank you for that. I am trying to learn Python (at 75 years young!), and having some problems with a blackjack program I'm trying to create. I corrected all the problems the program told me about except for the escape sequences in line 13. Also, how do I have it print out other cards but the one that I explicitly have in that line (7 of spades)?
    Thank you very much for your time.

    • @allenbennett8735
      @allenbennett8735 Рік тому

      I forgot to paste my code.
      import random
      # from tkinter import *
      from PIL import Image
      suit_color = ""
      global our_card_image
      suit = 0
      number_of_decks = input("Number of decks? ")
      deck = list(range(1, 53 * int(number_of_decks)+1))
      random.seed(0)
      random.shuffle(deck)
      deck = list(range(1, 53 * int(number_of_decks)+1))
      for i in range(1, 53 * int(number_of_decks)):
      our_card_image = Image.open("C:/Users/allen\OneDrive\Cards/7_of_spades.png")
      for i in range(1, 53 * int(number_of_decks)):
      match deck[i] % 13:
      case 1:
      value = "Ace"
      case 11:
      value = "Jack"
      case 12:
      value = "Queen"
      case 0:
      value = "King"
      case _:
      value = (deck[i] % 13)
      match ((deck[i] / 4)-(deck[i] // 4)) * 4:
      case 0:
      suit = "Clubs"
      case 1:
      suit = "Diamonds"
      case 2:
      suit = "Hearts"
      case 3:
      suit = "Spades"
      card = (str(value) + " of " + suit)
      match suit:
      case "Clubs" | "Spades":
      suit_color = "\033[1;30m"
      case "Diamonds" | "Hearts":
      suit_color = "\033[1;31m"
      # my_label = label(our_card_image)
      our_card_image.show()
      print(suit_color, card)

    • @emperor8716
      @emperor8716 Рік тому

      more power to you! i hope i'll be able to keep my brain turning at that age too.

    • @nicomal
      @nicomal Рік тому

      Have you tried asking OpenAI? It helped me this morning with some Python code.

  • @raghavsood28
    @raghavsood28 2 роки тому +2

    Hey, can you make a tutorial on how to make a game with java! That would be really cool.

  • @thepresistence5935
    @thepresistence5935 Рік тому

    13:45 I just used normal string 'red' it worked for me.

  • @maksoned0
    @maksoned0 2 роки тому +1

    Hello friend, can you pls make a tutorial of using "Perling Noise" in creating a Minecraft on Python project)

  • @usamaalshahmani-du3nw
    @usamaalshahmani-du3nw Рік тому

    i creat app py pillw and tkinter lib but i have a problim how i can use properties the image after add the image in the form
    thanks alot

  • @invisiblealex007
    @invisiblealex007 Рік тому

    is it possible to highlight image on a photo in certain aria? like to highlight a dog on the photo in one click?

  • @ticris
    @ticris Рік тому

    Hello. What do you use to draw on the screen?

  • @dabody123456
    @dabody123456 2 роки тому

    روح يا ابني ربنا يبركلك {F}

  • @anshulbindua9230
    @anshulbindua9230 2 роки тому +1

    Please make video on creating snake game on js with animation like Google snake game

  • @amongussussybaka69420
    @amongussussybaka69420 9 місяців тому

    In what folder should I put my image files?

  • @karthickkuduva9819
    @karthickkuduva9819 Рік тому

    Can I work with jupyter notebook for pillow?

  • @kurakburak4668
    @kurakburak4668 2 роки тому +5

    Hey, what happened to pytube tutorial video?

    • @joshkanyinda5569
      @joshkanyinda5569 2 роки тому

      I knew I wasn’t tripping when i went to my history and didn’t find it.

    • @ezequielsm
      @ezequielsm Рік тому

      the pysimplegui video was also deleted :(

  • @N0OBB
    @N0OBB 2 роки тому

    AttributeError: module 'PIL.Image' has no attribute 'Palette'
    I think i have a different version, but where to find Palette in my version?

    • @ClearCode
      @ClearCode  2 роки тому

      Hey, can you paste the whole line here?

  • @yuvraj4762
    @yuvraj4762 2 роки тому

    Hello sir, can u make a video in godot platformer

  • @hawkise
    @hawkise 2 роки тому +1

    Hey! thx for this video, really need it) also, can you tell us please, how to run python code in Sublime Text?? Would really appreciate it

    • @ClearCode
      @ClearCode  2 роки тому +2

      Press control + b

    • @hawkise
      @hawkise 2 роки тому

      @@ClearCode I tried it, but it's not for python 3.9 and input function, but thank you anyway)

    • @pranavnyavanandi9710
      @pranavnyavanandi9710 2 роки тому

      @@ClearCode The problem is that sublime does not take user input using the input() function in python.
      And not only python, it seems Sublime has an issue taking input across all languages, what can be done about this?
      Any eclipse/ vs-code like ide for Python? I have heard of PyCharm except it is paid.
      If you can make a video setting up a develipment environment in sublime, it would be nice.

    • @limeedhot
      @limeedhot 2 роки тому

      @@pranavnyavanandi9710 pycharm is not paid
      unless you do the paid version

    • @limeedhot
      @limeedhot 2 роки тому

      @@pranavnyavanandi9710 also if you really want to you can use vs-code with input()
      just go into the terminal, type the local path to the python file.
      like if your file layout is:
      games (folder):
      a_game.py
      you would type:
      python games/a_game.py
      because we go into games folder, then run a_game.py

  • @Dowdoo
    @Dowdoo 2 роки тому

    hey! can you tell me what programming software and what theme are you using?

    • @amber82872
      @amber82872 2 роки тому

      i think he is using sublime text. Dark theme i think

  • @avih5366
    @avih5366 2 роки тому +1

    1st viewers

  • @code_hero125
    @code_hero125 2 роки тому

    Hello sir can you please make video on pygame.midi

  • @imfito3713
    @imfito3713 2 роки тому

    In the image.transpose part i get an error saying: '' AttributeError: module 'PIL.Image' has no attribute 'Transpose' '' Tried to find a solution online but couldn't for anything that worked

    • @ClearCode
      @ClearCode  2 роки тому

      Can you show the full line here?

    • @imfito3713
      @imfito3713 2 роки тому

      @@ClearCode
      with Image.open("picture.jpg") as im:
      im_flipped = im.transpose(method=Image.Transpose.FLIP_LEFT_RIGHT)

    • @yourdad8228
      @yourdad8228 2 роки тому +1

      ​@@imfito3713
      from PIL import Image
      with Image.open("snorlax.jpg") as im:
      im_flipped = im.transpose(method=Image.FLIP_LEFT_RIGHT)
      im.show()
      It did work but I got a DeprecationWarning.
      DeprecationWarning: FLIP_LEFT_RIGHT is deprecated and will be removed in Pillow 10 (2023-07-01). Use Transpose.FLIP_LEFT_RIGHT instead.
      The new method is the way shown in the video. For some reason Pycharm is showing that Image.Transpose doesn't exist by highlighting it in yellow but it executes with no errors.

    • @anjohnnako3309
      @anjohnnako3309 Рік тому +1

      I've got the same error, but it worked using this line. image_flip_horizontal = image.transpose(Image.FLIP_LEFT_RIGHT). Removing the Transpose in Image.Transpose.FLIP_LEFT_RIGHT have fixed it.

  • @gloriouz89
    @gloriouz89 Рік тому

    Would you be able to tell me if Pillow can output an image in plain bytes? Like this
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0x7f, 0x7f, 0xff, 0xbf, 0xff, 0xff, 0xdf, 0xdf, 0xff, 0xff, 0xef, 0xef, 0xff,
    0xff, 0xff, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf7, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3, 0xf3,
    0xf3, 0xe3, 0xe3, 0xe3, 0xf3, 0xef, 0xc7, 0xc7, 0xe7, 0x87, 0x97, 0x07, 0x07, 0x0f, 0x0f, 0x0f,
    0x8f, 0x0f, 0x1f, 0x1f, 0x1f, 0x3f, 0x3f, 0x3f, 0x7f, 0x7f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,

  • @rajaryan7167
    @rajaryan7167 2 роки тому

    please make a full course on openCv python

    • @codingbuddy0415
      @codingbuddy0415 Рік тому

      Image Editor using Python & Pillow: Crop, rotate, resize, blur & More ua-cam.com/video/FeGSwIcQdpY/v-deo.html

  • @MR-er7zp
    @MR-er7zp 2 роки тому

    Hi, I watched your video about the pygame snake and I have one question: How can you implement the speed of the snake so that the speed increases when the snake grows?

    • @GabrielOliveira-nj9qg
      @GabrielOliveira-nj9qg 2 роки тому

      as the snake's size only increases when it comes to the apple, you can measure the apple, for example:
      if snake.colliderect(apple):
      speed += 0.2
      the problem is that if you use this variable speed to move the snake
      if RIGHT:
      x_snake += speed
      over time this will cause a small position bug that i'm still trying to solve. Or an example would be to use a
      clock.tick(speed)
      and use the speed as the FPS
      translated with Google

  • @epicgamerz509
    @epicgamerz509 2 роки тому

    Sir, can you make part 3 of minecraft from python please please please

  • @patjaproduction1119
    @patjaproduction1119 Рік тому

    51:57

  • @WisdomShortvids
    @WisdomShortvids Рік тому

    imageChops no longer in Pillow build

  • @sharonosaze
    @sharonosaze 5 місяців тому

    It read an error

  • @sharonosaze
    @sharonosaze 5 місяців тому

    Error

  • @giannhsp222
    @giannhsp222 Рік тому

    You sound bored

  • @user-cs5ke6fk4f
    @user-cs5ke6fk4f 2 роки тому +2

    import sqlite3
    import time
    class Song():
    def __init__(self, name, singer, album, production_company, song_duration):
    self.name = name
    self.singer = singer
    self.album = album
    self.production_company = production_company
    self.song_duration = song_duration
    def __str__(self):
    return f"Name: {self.name}
    " \
    f"Singer: {self.singer}
    " \
    f"Album: {self.album}
    " \
    f"Production Company {self.production_company}
    " \
    f"Song Duration: {self.song_duration}
    "
    class Library():
    def __init__(self):
    self.connection()
    def connection(self):
    self.con = sqlite3.connect("song_library.db")
    self.cursor = self.con.cursor()
    self.cursor.execute("Create Table if not exists songs (name TEXT, singer TEXT, album TEXT"
    "production_company TEXT, song_duration INT)")
    self.con.commit()
    def add_song(self, song_name):
    self.cursor.execute("Insert into songs Values (?, ?, ?, ?, ?)", (song_name.name,
    song_name.singer,
    song_name.album,
    song_name.production_company,
    song_name.song_duration))
    self.con.commit()
    def show_song(self, song_name):
    self.cursor.execute("select * from songs where name = ?", (song_name,))
    song = self.cursor.fetchall()
    if len(song) == 0:
    print("There is no such book...")
    else:
    song = Song(song[0][0], song[0][1], song[0][2], song[0][3], song[0][4])
    print(song)
    def show_songs(self):
    self.cursor.execute("select * from songs")
    songs = self.cursor.fetchall()
    for i in songs:
    print(i)
    while True:
    print("""***********************
    welcome to song program
    transactions;
    1. Add Song
    2. Show Song
    3. Show Songs
    ***********************""")
    transaction = input("Please Chose One Transaction...")
    if transaction == "1":
    name = input("Name:")
    singer = input("Singer:")
    album = input("Album:")
    production_company = input("Production Company:")
    song_duration = input("Song Duratinon:")
    new_song = Song(name, singer, album, production_company, song_duration)
    print("Adding Song...")
    time.sleep(1)
    Library.add_song(new_song)
    print("Transaction Finished...")
    if transaction == "2":
    song = input("Song:")
    Library.add_song(song)
    if transaction == "3":
    Library.show_songs()
    else:
    continue
    what is wron in that

    • @pranavnyavanandi9710
      @pranavnyavanandi9710 2 роки тому

      What error did it give? Post that here. I'll try to look at it.

  • @michalbotor
    @michalbotor Рік тому

    img.convert('L') # meh..
    ImageEnhance.Contrast(img).enhance(1.25).convert('L') # nice!

  • @ashuzon
    @ashuzon 4 місяці тому

    Thank you!