Skip to content

Commit f125c8c

Browse files
committed
Create imageConversions.py
BMP's to JPG's GIF's to JPG's (first frame only)
1 parent e701f34 commit f125c8c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

imageConversions.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Image
2+
import sys
3+
4+
# Will only convert first frame of gif to jpeg
5+
def gifToJpg(infile):
6+
file_name = infile[:infile.rfind('.')]
7+
8+
try:
9+
im = Image.open(infile)
10+
except IOError:
11+
return False
12+
13+
mypalette = im.getpalette()
14+
15+
im.putpalette(mypalette)
16+
new_im = Image.new("RGBA", im.size)
17+
new_im.paste(im)
18+
new_im.save(file_name + '.jpg', 'JPEG')
19+
20+
def bmpToJpg(infile):
21+
file_name = infile[:infile.rfind('.')]
22+
23+
try:
24+
im = Image.open(infile)
25+
except IOError:
26+
return False
27+
28+
im.save(file_name + '.jpg', "JPEG")

0 commit comments

Comments
 (0)