-
Notifications
You must be signed in to change notification settings - Fork 26
/
image_converter.py
44 lines (32 loc) · 1.09 KB
/
image_converter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from PIL import Image
import sys
try:
fullimageFileName = sys.argv[1]
operation = sys.argv[2]
argument = sys.argv[3]
if operation == '-f':
r = fullimageFileName.split('.')
imageFileName = r[0]
im = Image.open(fullimageFileName)
converted = im.convert('RGB')
converted.save(f'{imageFileName}t.{argument}')
elif operation == '-r':
im = Image.open(fullimageFileName)
r = argument.split('x')
r_tuple = (int(r[0]), int(r[1]))
out = im.resize(r_tuple)
out.save(f'output_{fullimageFileName}')
except:
print('Usage of converter')
print('command:')
print('python resizer.py [input file name] [operation] [argument]')
print('Operation to be carried: ')
print('-f : format image')
print('Example:')
print('1: python resizer.py image.jpeg -f png ')
print('2: python resizer.py image.png -f jpeg ')
print()
print('-r :To resize image')
print('Example:')
print('1: python resizer.py image.jpeg -r 200x200 ')
print('2: python resizer.py image.jpeg -r 250x200 ')