Last active
January 2, 2022 11:33
-
-
Save conquistadorjd/2c93de1d95fa1a953c2221efc4420c4b to your computer and use it in GitHub Desktop.
Revisions
-
Pravin revised this gist
Feb 11, 2019 . 1 changed file with 46 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ ################################################################################################ # name: 06_crop_image_01.py # desc: # date: 2019-02-10 # Author: conquistadorjd ################################################################################################ from PIL import Image, ImageDraw print('*** Program Started ***') # image_font_path = 'imagepath_input = '/home/conquistador/code/github/python-01-utilities/image/fonts/' image_path_input = '/home/conquistador/code/github/python-01-utilities/image/input/' image_path_output = '/home/conquistador/code/github/python-01-utilities/image/output/' image_name_input = '06_crop_image_01_input.jpg' ###################################################### im = Image.open(image_path_input + image_name_input) im_width, im_height = im.size print('im.size', im.size) ###################################################### Left half of the image im = im.crop((0, 0, im_width/2,im_height)) # (left, upper, right, lower)-tuple. image_name_output = '06_crop_image_01_output_01.jpg' im.save(image_path_output + image_name_output) print('im.size', im.size) ###################################################### right half of the image im = Image.open(image_path_input + image_name_input) im = im.crop((im_width/2, 0, im_width, im_height)) image_name_output = '06_crop_image_01_output_02.jpg' im.save(image_path_output + image_name_output) print('im.size', im.size) ###################################################### right top half of the image im = Image.open(image_path_input + image_name_input) im = im.crop((im_width/2, 0, im_width, im_height/2)) image_name_output = '06_crop_image_01_output_03.jpg' im.save(image_path_output + image_name_output) print('im.size', im.size) print('*** Program Ended ***') -
Pravin revised this gist
Feb 11, 2019 . 1 changed file with 10 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,18 +13,21 @@ image_font_path = '/home/conquistador/code/github/python-01-utilities/image/fonts/' image_path_input = '/home/conquistador/code/github/python-01-utilities/image/input/' image_path_output = '/home/conquistador/code/github/python-01-utilities/image/output/' # image_name_input = '05_compress_image_01_input.png' image_name_input = '05_compress_image_01_input.jpg' im = Image.open(image_path_input + image_name_input) print('Input file size : ', im.size ) print('Input file name : ', image_name_input ) print('Input Image Size : ', os.path.getsize (image_path_input + image_name_input)) # image_name_output = '05_compress_image_01_output.png' image_name_output = '05_compress_image_01_output.jpg' im.save(image_path_output + image_name_output ,optimize=True,quality=50) print('Output file size : ', im.size ) print('Output file name : ', image_name_output) print('Output Image Size : ', os.path.getsize (image_path_output + image_name_output)) print('*** Program Ended ***') -
Pravin revised this gist
Feb 11, 2019 . 1 changed file with 30 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ ################################################################################################ # name: 05_compress_image_01.py # desc: Compress image file using python # date: 2019-02-10 # Author: conquistadorjd ################################################################################################ from PIL import Image, ImageDraw, ImageFont import os print('*** Program Started ***') image_font_path = '/home/conquistador/code/github/python-01-utilities/image/fonts/' image_path_input = '/home/conquistador/code/github/python-01-utilities/image/input/' image_path_output = '/home/conquistador/code/github/python-01-utilities/image/output/' image_name_input = '05_compress_image_01_input.png' # image_name_input = '05_compress_image_01_input.jpg' im = Image.open(image_path_input + image_name_input) image_name_output = '05_compress_image_01_output.png' # image_name_output = '05_compress_image_01_output.jpg' im.save(image_path_output + image_name_output ,optimize=True,quality=50) print('Input file name :', image_name_input ) print('Output file name :', image_name_output) print('Input Image Size : ', os.path.getsize (image_path_input + image_name_input)) print('Output Image Size : ', os.path.getsize (image_path_output + image_name_output)) print('*** Program Ended ***') -
Pravin revised this gist
Feb 11, 2019 . 2 changed files with 62 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ ################################################################################################ # name: 04_resize_image_01.py # desc: reducing the file size and keeping same aspect ratio # date: 2019-02-10 # Author: conquistadorjd ################################################################################################ from PIL import Image, ImageDraw print('*** Program Started ***') # image_font_path = 'imagepath_input = '/home/conquistador/code/github/python-01-utilities/image/fonts/' image_path_input = '/home/conquistador/code/github/python-01-utilities/image/input/' image_path_output = '/home/conquistador/code/github/python-01-utilities/image/output/' image_name_input = '04_resize_image_01_input.jpg' ###################################################### im = Image.open(image_path_input + image_name_input) im_width, im_height = im.size print('im.size', im.size) im = im.resize((int(im_width/2), int(im_height/2)), Image.ANTIALIAS) # im = im.resize((im_width,im_height), Image.LANCZOS) print('im.size', im.size) image_name_output = '04_resize_image_01_output.jpg' im.save(image_path_output + image_name_output) print('*** Program Ended ***') This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ ################################################################################################ # name: 04_resize_image_02.py # desc: reducing the file size but changing the aspect ratio # date: 2019-02-10 # Author: conquistadorjd ################################################################################################ from PIL import Image, ImageDraw print('*** Program Started ***') # image_font_path = 'imagepath_input = '/home/conquistador/code/github/python-01-utilities/image/fonts/' image_path_input = '/home/conquistador/code/github/python-01-utilities/image/input/' image_path_output = '/home/conquistador/code/github/python-01-utilities/image/output/' image_name_input = '04_resize_image_01_input.jpg' ###################################################### im = Image.open(image_path_input + image_name_input) im_width, im_height = im.size print('im.size', im.size) im = im.resize(( 500,480 ), Image.ANTIALIAS) # im = im.resize((im_width,im_height), Image.LANCZOS) print('im.size', im.size) image_name_output = '04_resize_image_02_output.jpg' im.save(image_path_output + image_name_output) print('*** Program Ended ***') -
Pravin revised this gist
Feb 11, 2019 . 2 changed files with 63 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ ################################################################################################ # name: 03_add_text_to_image_01.py # desc: # date: 2019-02-10 # Author: conquistadorjd ################################################################################################ from PIL import Image, ImageDraw, ImageFont print('*** Program Started ***') image_font_path = '/home/conquistador/code/github/python-01-utilities/image/fonts/' image_path_input = '/home/conquistador/code/github/python-01-utilities/image/input/' image_path_output = '/home/conquistador/code/github/python-01-utilities/image/output/' image_name_input = '03_add_text_to_image_01_input.jpg' ######################################################################## Writing simple text on file im = Image.open(image_path_input + image_name_input) position = (50, 50) message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit" # initialise the drawing context with the image object as background draw = ImageDraw.Draw(im) draw.text(position, message) im.show() image_name_output = '03_add_text_to_image_01_input_01.jpg' im.save(image_path_output + image_name_output) print('*** Program Ended ***') This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ ################################################################################################ # name: 03_add_text_to_image_02.py # desc: # date: 2019-02-10 # Author: conquistadorjd ################################################################################################ from PIL import Image, ImageDraw, ImageFont print('*** Program Started ***') image_font_path = '/home/conquistador/code/github/python-01-utilities/image/fonts/' image_path_input = '/home/conquistador/code/github/python-01-utilities/image/input/' image_path_output = '/home/conquistador/code/github/python-01-utilities/image/output/' image_name_input = '03_add_text_to_image_01_input.jpg' im = Image.open(image_path_input + image_name_input) position = (50, 50) message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit" font = ImageFont.truetype(image_font_path + 'Unkempt-Regular.ttf', size=24) color = (238, 242, 4) # initialise the drawing context with the image object as background draw = ImageDraw.Draw(im) draw.text(position, message, fill=color, font=font) im.show() image_name_output = '03_add_text_to_image_02_input_01.jpg' im.save(image_path_output + image_name_output) print('*** Program Ended ***') -
Pravin revised this gist
Feb 11, 2019 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,16 +11,17 @@ # image_font_path = 'imagepath_input = '/home/conquistador/code/github/python-01-utilities/image/fonts/' # image_path_input = '/home/conquistador/code/github/python-01-utilities/image/input/' image_path_output = '/home/conquistador/code/github/python-01-utilities/image/output/' # image_name_input = '02_create_blank_image_01.jpg' image_name_output = '02_create_blank_image_01.jpg' mode = 'RGB' # for color image “L” (luminance) for greyscale images, “RGB” for true color images, and “CMYK” for pre-press images. size = (640, 480) color = (73, 109, 137) im = Image.new(mode, size, color) im.save(image_path_output + image_name_output ) im.show() print('*** Program Ended ***') -
Pravin revised this gist
Feb 11, 2019 . 1 changed file with 26 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ ################################################################################################ # name: 02_create_blank_image.py # desc: Creates blank image files # date: 2019-02-10 # Author: conquistadorjd ################################################################################################ from PIL import Image, ImageDraw print('*** Program Started ***') # image_font_path = 'imagepath_input = '/home/conquistador/code/github/python-01-utilities/image/fonts/' # image_path_input = '/home/conquistador/code/github/python-01-utilities/image/input/' image_path_output = '/home/conquistador/code/github/python-01-utilities/image/output/' image_name_input = '02_create_blank_image_01.jpg' mode = 'RGB' # for color image “L” (luminance) for greyscale images, “RGB” for true color images, and “CMYK” for pre-press images. size = (640, 480) color = (73, 109, 137) im = Image.new(mode, size, color) im.save(image_path_output + image_name_input ) im.show() print('*** Program Ended ***') -
Pravin revised this gist
Feb 11, 2019 . 1 changed file with 10 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,13 +12,20 @@ # image_font_path = 'imagepath_input = '/home/conquistador/code/github/python-01-utilities/image/fonts/' image_path_input = '/home/conquistador/code/github/python-01-utilities/image/input/' # image_path_output = '/home/conquistador/code/github/python-01-utilities/image/output/' image_name_input = '01_read_image.jpg' im = Image.open(image_path_input + image_name_input) print('im object: ', im) print('format : ' , im.format) print('size : ' , im.size) print('mode : ' , im.mode) print('filename : ' , im.filename) print('width : ' , im.width) print('height : ' , im.height) print('info : ' , im.info) # This will display image on screen # im.show() print('*** Program Ended ***') -
Pravin created this gist
Feb 11, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ image processing This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ ################################################################################################ # name: 01_read_image.py # desc: # date: 2019-02-10 # Author: conquistadorjd ################################################################################################ from PIL import Image print('*** Program Started ***') # image_font_path = 'imagepath_input = '/home/conquistador/code/github/python-01-utilities/image/fonts/' image_path_input = '/home/conquistador/code/github/python-01-utilities/image/input/' # image_path_output = '/home/conquistador/code/github/python-01-utilities/image/output/' image_name_input = '20170708-sky-1873934_1920.jpg' im = Image.open(image_path_input + image_name_input) print('im : ',im) print('Attributes : ', im.format, im.size, im.mode,im.filename, im.width, im.height, im.info) # im.show() print('*** Program Ended ***')