forked from kookmin-sw/cap-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from kookmin-sw/feat/flask_server
Feat/flask server
- Loading branch information
Showing
6 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ predict_image/* | |
|
||
__pycache__ | ||
.vscode | ||
*.idea | ||
*.idea | ||
.env |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from PIL import Image | ||
import os | ||
|
||
def resize_img(path): | ||
image_path = path | ||
image = Image.open(image_path) | ||
file_name = os.path.basename(path) | ||
|
||
# 이미지 회전 상태 확인 | ||
orientation = 1 # 기본적으로 회전되지 않은 상태 | ||
if hasattr(image, '_getexif'): # Exif 정보가 있는지 확인 | ||
exif = image._getexif() # Exif 정보 가져오기 | ||
if exif is not None: | ||
orientation = exif.get(0x0112, 1) | ||
|
||
# 이미지 크기 조정 | ||
new_resolution = (1024, 1024) | ||
resized_image = image.resize(new_resolution) | ||
|
||
# 회전된 이미지 원래대로 돌리기 | ||
if orientation in [3, 6, 8]: | ||
if orientation == 3: | ||
resized_image = resized_image.transpose(Image.ROTATE_180) | ||
elif orientation == 6: | ||
resized_image = resized_image.transpose(Image.ROTATE_270) | ||
elif orientation == 8: | ||
resized_image = resized_image.transpose(Image.ROTATE_90) | ||
|
||
resized_image.save(f"./gan/input/{file_name}") | ||
print("조정된 이미지 경로:", f"./gan/input/{file_name}" ) | ||
print("조정된 이미지 크기:", resized_image.size) |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import smtplib # SMTP 사용을 위한 모듈 | ||
import re # Regular Expression을 활용하기 위한 모듈 | ||
from email.mime.multipart import MIMEMultipart # 메일의 Data 영역의 메시지를 만드는 모듈 | ||
from email.mime.text import MIMEText # 메일의 본문 내용을 만드는 모듈 | ||
from email.mime.image import MIMEImage # 메일의 이미지 파일을 base64 형식으로 변환하기 위한 모듈 | ||
|
||
def sendEmail(receiver, image_path, sender, sender_pw): | ||
# 유효성 검사를 위한 정규표현식 | ||
reg = "^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$" | ||
if re.match(reg, receiver): | ||
print("정상적인 메일 형식 확인 완료 --> 메일 전송 중") | ||
else: | ||
print("받으실 메일 주소가 정확하지 않습니다.") | ||
return False | ||
|
||
# 이메일 형식이 맞을 경우만 진행됨. | ||
# smpt 서버와 연결 | ||
smtp_server = "smtp.gmail.com" | ||
port = 587 | ||
smtp = smtplib.SMTP(smtp_server, port) | ||
smtp.starttls() | ||
|
||
# 로그인 | ||
smtp.login(sender, sender_pw) | ||
|
||
# 메일 내용 구성 | ||
msg = MIMEMultipart() | ||
msg["Subject"] = "Only You" | ||
msg["From"] = sender | ||
msg["To"] = receiver | ||
|
||
content = '''\ | ||
안녕하세요. Capstone 11조 Only You입니다. | ||
요청하신 이미지 생성이 완료되어 이메일로 전송해드립니다. | ||
좋은 하루 보내세요~!\ | ||
''' | ||
|
||
content_part = MIMEText(content, "plain") | ||
msg.attach(content_part) | ||
|
||
# image 추가 | ||
with open(image_path, 'rb') as file: | ||
img = MIMEImage(file.read()) | ||
img.add_header('Content-Disposition', 'attachment', filename = "image.jpg") | ||
msg.attach(img) | ||
|
||
smtp.sendmail(sender, receiver, msg.as_string()) | ||
|
||
smtp.quit() | ||
return True | ||
|
This file contains 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 characters