
import time
from PIL import Image, ImageFilter
import concurrent.futures

image_input_folder = 'original'
image_output_folder = 'processed'

img_names = [
    'photo-1564135624576-c5c88640f235.jpg',
    'photo-1550439062-609e1531270e.jpg',
    'photo-1549692520-acc6669e2f0c.jpg',
    'photo-1541698444083-023c97d3f4b6.jpg',
    'photo-1532009324734-20a7a5813719.jpg',
    'photo-1530224264768-7ff8c1789d79.jpg',
    'photo-1530122037265-a5f1f91d3b99.jpg',
    'photo-1524429656589-6633a470097c.jpg',
    'photo-1516972810927-80185027ca84.jpg',
    'photo-1516117172878-fd2c41f4a759.jpg',
    'photo-1513938709626-033611b8cc03.jpg',
    'photo-1507143550189-fed454f93097.jpg',
    'photo-1504198453319-5ce911bafcde.jpg',
    'photo-1493976040374-85c8e12f0c0e.jpg'
]

def process_image(img_name) :
    size = (120, 120)
    img = Image.open(f'{image_input_folder}/{img_name}')
    img = img.filter(ImageFilter.GaussianBlur(15))
    img.thumbnail(size)
    img.save(f'{image_output_folder}/{img_name}')
    print(f'{image_output_folder}/{img_name} was processed ...')

if __name__ == '__main__':
    t1 = time.perf_counter()

    # Process보다 Thread가 약간 빠르긴 한데
    # Thread의 메모리 점유 상황이 그렇게 좋지 않다.
    # with concurrent.futures.ProcessPoolExecutor() as executor:
    #     executor.map(process_image, img_names)


    with concurrent.futures.ThreadPoolExecutor() as executor:
        executor.map(process_image, img_names)

    t2 = time.perf_counter()

    print(f'Finished in {t2-t1} second(s)')


9cfcca4596fb739e66955c56ff7545308aaad529
<mask token>


def process_image(img_name):
    size = 120, 120
    img = Image.open(f'{image_input_folder}/{img_name}')
    img = img.filter(ImageFilter.GaussianBlur(15))
    img.thumbnail(size)
    img.save(f'{image_output_folder}/{img_name}')
    print(f'{image_output_folder}/{img_name} was processed ...')


<mask token>

<mask token>


def process_image(img_name):
    size = 120, 120
    img = Image.open(f'{image_input_folder}/{img_name}')
    img = img.filter(ImageFilter.GaussianBlur(15))
    img.thumbnail(size)
    img.save(f'{image_output_folder}/{img_name}')
    print(f'{image_output_folder}/{img_name} was processed ...')


if __name__ == '__main__':
    t1 = time.perf_counter()
    with concurrent.futures.ThreadPoolExecutor() as executor:
        executor.map(process_image, img_names)
    t2 = time.perf_counter()
    print(f'Finished in {t2 - t1} second(s)')

<mask token>
image_input_folder = 'original'
image_output_folder = 'processed'
img_names = ['photo-1564135624576-c5c88640f235.jpg',
    'photo-1550439062-609e1531270e.jpg',
    'photo-1549692520-acc6669e2f0c.jpg',
    'photo-1541698444083-023c97d3f4b6.jpg',
    'photo-1532009324734-20a7a5813719.jpg',
    'photo-1530224264768-7ff8c1789d79.jpg',
    'photo-1530122037265-a5f1f91d3b99.jpg',
    'photo-1524429656589-6633a470097c.jpg',
    'photo-1516972810927-80185027ca84.jpg',
    'photo-1516117172878-fd2c41f4a759.jpg',
    'photo-1513938709626-033611b8cc03.jpg',
    'photo-1507143550189-fed454f93097.jpg',
    'photo-1504198453319-5ce911bafcde.jpg',
    'photo-1493976040374-85c8e12f0c0e.jpg']


def process_image(img_name):
    size = 120, 120
    img = Image.open(f'{image_input_folder}/{img_name}')
    img = img.filter(ImageFilter.GaussianBlur(15))
    img.thumbnail(size)
    img.save(f'{image_output_folder}/{img_name}')
    print(f'{image_output_folder}/{img_name} was processed ...')


if __name__ == '__main__':
    t1 = time.perf_counter()
    with concurrent.futures.ThreadPoolExecutor() as executor:
        executor.map(process_image, img_names)
    t2 = time.perf_counter()
    print(f'Finished in {t2 - t1} second(s)')

import time
from PIL import Image, ImageFilter
import concurrent.futures
image_input_folder = 'original'
image_output_folder = 'processed'
img_names = ['photo-1564135624576-c5c88640f235.jpg',
    'photo-1550439062-609e1531270e.jpg',
    'photo-1549692520-acc6669e2f0c.jpg',
    'photo-1541698444083-023c97d3f4b6.jpg',
    'photo-1532009324734-20a7a5813719.jpg',
    'photo-1530224264768-7ff8c1789d79.jpg',
    'photo-1530122037265-a5f1f91d3b99.jpg',
    'photo-1524429656589-6633a470097c.jpg',
    'photo-1516972810927-80185027ca84.jpg',
    'photo-1516117172878-fd2c41f4a759.jpg',
    'photo-1513938709626-033611b8cc03.jpg',
    'photo-1507143550189-fed454f93097.jpg',
    'photo-1504198453319-5ce911bafcde.jpg',
    'photo-1493976040374-85c8e12f0c0e.jpg']


def process_image(img_name):
    size = 120, 120
    img = Image.open(f'{image_input_folder}/{img_name}')
    img = img.filter(ImageFilter.GaussianBlur(15))
    img.thumbnail(size)
    img.save(f'{image_output_folder}/{img_name}')
    print(f'{image_output_folder}/{img_name} was processed ...')


if __name__ == '__main__':
    t1 = time.perf_counter()
    with concurrent.futures.ThreadPoolExecutor() as executor:
        executor.map(process_image, img_names)
    t2 = time.perf_counter()
    print(f'Finished in {t2 - t1} second(s)')


import time
from PIL import Image, ImageFilter
import concurrent.futures

image_input_folder = 'original'
image_output_folder = 'processed'

img_names = [
    'photo-1564135624576-c5c88640f235.jpg',
    'photo-1550439062-609e1531270e.jpg',
    'photo-1549692520-acc6669e2f0c.jpg',
    'photo-1541698444083-023c97d3f4b6.jpg',
    'photo-1532009324734-20a7a5813719.jpg',
    'photo-1530224264768-7ff8c1789d79.jpg',
    'photo-1530122037265-a5f1f91d3b99.jpg',
    'photo-1524429656589-6633a470097c.jpg',
    'photo-1516972810927-80185027ca84.jpg',
    'photo-1516117172878-fd2c41f4a759.jpg',
    'photo-1513938709626-033611b8cc03.jpg',
    'photo-1507143550189-fed454f93097.jpg',
    'photo-1504198453319-5ce911bafcde.jpg',
    'photo-1493976040374-85c8e12f0c0e.jpg'
]

def process_image(img_name) :
    size = (120, 120)
    img = Image.open(f'{image_input_folder}/{img_name}')
    img = img.filter(ImageFilter.GaussianBlur(15))
    img.thumbnail(size)
    img.save(f'{image_output_folder}/{img_name}')
    print(f'{image_output_folder}/{img_name} was processed ...')

if __name__ == '__main__':
    t1 = time.perf_counter()

    # Process보다 Thread가 약간 빠르긴 한데
    # Thread의 메모리 점유 상황이 그렇게 좋지 않다.
    # with concurrent.futures.ProcessPoolExecutor() as executor:
    #     executor.map(process_image, img_names)


    with concurrent.futures.ThreadPoolExecutor() as executor:
        executor.map(process_image, img_names)

    t2 = time.perf_counter()

    print(f'Finished in {t2-t1} second(s)')

