Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions DIYgod/0005/change_resolution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-

from PIL import Image

def change_resolution(picPath, reslution):
img = Image.open(picPath)
x, y = img.size
print x, y
changex = float(x) / reslution[0]
changey = float(y) / reslution[1]

# 判断分辨率是否满足
if changex > 1 or changey > 1:
change = changex if changex > changey else changey
print change
print int(reslution[0] / change), int(reslution[1] / change)
img.resize((int(x / change), int(y / change))).save('result.jpg')

if __name__ == '__main__':
change_resolution('pictest.jpg', (1136, 640))
Binary file added DIYgod/0005/pictest.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DIYgod/0005/result.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions DIYgod/0006/important_word.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-

import re
import os

# Get all files in designated path
def get_files(path):
filepath = os.listdir(path)
files = []
for fp in filepath:
fppath = path + '/' + fp
if(os.path.isfile(fppath)):
files.append(fppath)
elif(os.path.isdir(fppath)):
files += get_files(fppath)
return files

# Get the most popular word in designated files
def get_important_word(files):
worddict = {}
for filename in files:
f = open(filename, 'rb')
s = f.read()
words = re.findall(r'[a-zA-Z0-9]+', s)
for word in words:
worddict[word] = worddict[word] + 1 if word in worddict else 1
wordsort = sorted(worddict.items(), key=lambda e:e[1], reverse=True)
return wordsort

if __name__ == '__main__':
files = get_files('.')
print files
print get_important_word(files)
2 changes: 2 additions & 0 deletions DIYgod/0006/test/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
important important important important important important important important important important important important important important important important important important important