Это видео недоступно.
Сожалеем об этом.

Python Resize Multiple Images

Поделиться
HTML-код
  • Опубликовано: 13 авг 2024
  • In this Python Pillow tutorial, we will go over how to display image properties, preview images, loop through a set of images, create a list of images, and resize multiple images.

Комментарии • 35

  • @RyanNoonan
    @RyanNoonan  4 года назад +12

    Here is another example that saves the resized images in a new folder with the existing filename.
    from PIL import Image
    import glob
    import os
    # new folder path (may need to alter for Windows OS)
    # change path to your path
    path = 'path/Resized_Shapes'
    # create new folder
    if not os.path.exists(path):
    os.makedirs(path)
    # loop over existing images and resize
    # change path to your path
    for filename in glob.glob('path/Shapes/*.png'):
    img = Image.open(filename).resize((1200,1200))
    # save resized images to new folder with existing filename
    img.save('{}{}{}'.format(path,'/',os.path.split(filename)[1]))

    • @massimomancini5371
      @massimomancini5371 3 года назад

      Thanks Ryan, in a blink of an eye resized thousands of images. Great

    • @creativity9477
      @creativity9477 3 года назад +1

      this is not showing me any output in the output folder

    • @RyanNoonan
      @RyanNoonan  3 года назад

      Make sure the paths are correct. I just tested the code and it works on Mac and PC. If using PC make path string a raw string or using double backslashes.

  • @SaurabhSharma-qi1ck
    @SaurabhSharma-qi1ck 5 лет назад +2

    I was beating my head for this and found the solution, thanks man!

  • @wowleo8563
    @wowleo8563 4 года назад +1

    Very nice video, just jump right into coding, no excessive talking, I love it, keep up the good work.

  • @garyhorne1134
    @garyhorne1134 2 года назад

    I tried this, but get an error Traceback with im = image.open(img_path) ? but cannot see why.
    import glob
    img_path = '/Volumes/Elements/PlmEvents/PrintTest/Capture03.jpg'
    im = image.open(img_path)
    print('{}' .format(im.format))
    print('size/; {}' .format(im.size))
    print('image mode: {}') .format(im.mode)
    im.show()

    • @RyanNoonan
      @RyanNoonan  2 года назад

      Are you on a Mac or Windows machine? My first guess is that the path does not look right. Is that the full path? If you are on Windows, you may need to put in double slashes or make it a raw string. If you are on a Mac, find the image file, right click, hit the option key and copy as path name - for the full path name. Or you can put the image file in your working directory and just use the image file name and extension.

  • @yuvaldavid1363
    @yuvaldavid1363 2 года назад +1

    this video is very helpful, thanks :)

  • @artenquirer4068
    @artenquirer4068 4 года назад

    Thank you, Ryan! Thank you, Guido von Rossum! #python #jupyternotebook

  • @enginecompsecurity8398
    @enginecompsecurity8398 3 года назад +2

    Thank you man

  • @amankinde6610
    @amankinde6610 2 года назад +1

    Thank you bro

  • @amankinde6610
    @amankinde6610 2 года назад

    shall you add zooming , scalling ,.... using python sir

  • @MariaDiaz-qv7xy
    @MariaDiaz-qv7xy 3 года назад +1

    muchas gracias, me ayudó mucho!

  • @C0NN0C
    @C0NN0C 4 года назад +1

    Cheers! Plain and simple - and works!

  • @alperenergan
    @alperenergan 4 года назад +1

    thanks a lot

  • @burakkahveci4123
    @burakkahveci4123 4 года назад +1

    Thanks

  • @xperiax10minipro
    @xperiax10minipro 4 года назад

    Hi.
    How can i save these resized files by their original name, but in a new folder? and not rename it?

    • @RyanNoonan
      @RyanNoonan  4 года назад +2

      Use the same filename in save. This will overwrite so keep a copy of the original images if needed.
      for filename in glob.glob('path/*.jpeg'):
      img = Image.open(filename).resize((350,350))
      img.save(filename)

  • @ananyasaloi8620
    @ananyasaloi8620 3 года назад

    showing the error print{'{}'.format(im.format)}
    ^
    SyntaxError: invalid syntax

    • @RyanNoonan
      @RyanNoonan  3 года назад

      print() uses round brackets, not curly brackets.

  • @katiejames8278
    @katiejames8278 4 года назад

    Hi, thanks for this. How can this be used to resize image files with multiple extensions? ie to resize all files in a folder irrespective of the extension

    • @RyanNoonan
      @RyanNoonan  4 года назад +1

      Let me look into and I'll try to get back to you.

    • @katiejames8278
      @katiejames8278 4 года назад

      Thank you.

    • @RyanNoonan
      @RyanNoonan  4 года назад

      Code below resizes images with different types/extensions. I have not tried with all image types/extensions but works with jpg and png as an example. Also, a side note, if the originals should not be changed, keep a backup somewhere they can't be overwritten.
      from PIL import Image
      import glob
      import os
      # change path to your path
      # create list of paths to different images
      # list of different image types/extensions (add extensions as needed)
      img_types = ['*.JPG', '*.png']
      images = []
      for i in img_types:
      images.extend(glob.glob(f'/Users/username/Desktop/Shapes/{i}'))
      # create new folder
      new_folder = '/Users/username/Desktop/Resized_Images'
      if not os.path.exists(new_folder):
      os.makedirs(new_folder)
      # resize images and save to new folder
      for i in images:
      img = Image.open(i).resize((100,100))
      img.save(f'{new_folder}/{os.path.split(i)[1]}')

    • @zahiazineb
      @zahiazineb 2 года назад

      @@RyanNoonan thank u so much u don't know how much time u saved me with this code

  • @beastly572
    @beastly572 3 года назад

    Hi, thank you! It works! you rock. Would it require much to turn this into a program that I can put on my website? :D

    • @RyanNoonan
      @RyanNoonan  3 года назад

      Thanks. I have not tried to turn this into a website program, etc. yet. I'll try to look into that sometime.

    • @beastly572
      @beastly572 3 года назад

      @@RyanNoonan Thanks bud. By the way, is there any way to create a new folder on Desktop to save the files in? For instance a friend of mine would like to use a program like this. I dont know how to retrieve their PC username, since it's different to mine. I hope you know what I mean. Completely beginner to Python here.. so I basically have no idea

    • @beastly572
      @beastly572 3 года назад

      For them to pick destination folder would require some kind of GUI?

    • @RyanNoonan
      @RyanNoonan  3 года назад

      To create a new folder for files on your computer, see my pinned comment at the top for an example. You would just need to put in the path(s). Does that help?

    • @beastly572
      @beastly572 3 года назад

      @@RyanNoonan Yes, it makes sense. What i'm wondering tho, is how other people can save on their desktop without editing the code. To have some kind of save destination input.

  • @mochammadzulfikar9425
    @mochammadzulfikar9425 3 года назад

    I can't resize please help me