티스토리 뷰
- CombinImages(params) : 다수 이미지를 결합
- AddPrice2Image(params) : 이미지에 가격표 부착
- SaveWebImage(imageURL) : 웹이미지를 파일로 저장
- MakeTextImage(textData, imageName) : 텍스트가 포함된 이미지 만들기
def CombineImages(self, params):
imageSizeX = params.get('ImageSizeX')
imageSizeY = params.get('ImageSizeY')
imageNumberX = params.get('ImageNumberX')
imageNumberY = params.get('ImageNumberY')
imagePaths = params.get('ImagePaths')
imageFilename = params.get('ImageFilename')
newImage = Image.new("RGB", (imageSizeX, imageSizeY), 300000)
divSizeX = int((imageSizeX - 10 - ((imageNumberX-1)*10))/imageNumberX)
divSizeY = int((imageSizeY - 10 - ((imageNumberY-1)*10))/imageNumberY)
print("[divX]{}, [divY]{}", divSizeX, divSizeY)
indexX = 0
indexY = 0
for imagePath in imagePaths:
if indexX >= imageNumberX:
indexX = 0
indexY += 1
image1 = Image.open(imagePath)
image1 = image1.resize((divSizeX, divSizeY))
posX = (indexX*(divSizeX+10))+5
posY = (indexY*(divSizeY+10))+5
print("[posX]", posX, ", [posY]", indexY)
newImage.paste(image1, (posX, posY))
indexX += 1
newImage.show()
#newImage.save(newImagename)
#print("[New Image]", newImagename)
def SaveWebImage(self, imageURL):
image = requests.get(imageURL).content
fileName = os.path.basename(imageURL)
print("[Filename]", fileName)
with open(fileName, 'wb') as f:
f.write(image)
return fileName
def MakeTextImage(self, textData=None, savedImagePathname=None):
if not textData: textData = "Text-Data"
if not savedImagePathname: savedImagePathname = "Image002.jpg"
fontPath = "C:/Users/LOGINID/AppData/Local/Microsoft/Windows/Fonts"
fontName = "NanumGothic.ttf"
fontSize = 20
width_TextImage = 190
height_TextImage = 40
textPositionX = 10
textPositionY = 10
image1 = Image.new("RGB", (width_TextImage, height_TextImage), color=(100, 100, 10))
textFont = ImageFont.truetype(fontPath+"/"+fontName, fontSize, encoding="UTF-8")
imageD = ImageDraw.Draw(image1)
imageD.text((textPositionX, textPositionY), textData, font=textFont, fill=(255,255,255))
#image1.show()
image1.save(savedImagePathname)
return savedImagePathname
반응형
'SWDesk' 카테고리의 다른 글
[PHP, Python] JSON Test (0) | 2021.07.10 |
---|---|
[Android, PHP] JSON Test (0) | 2021.07.07 |
[Python] Download Google Images (0) | 2021.06.29 |
[Python] Sharing Google Spreadsheet (0) | 2021.06.29 |
[Python] Sentence Similarity (0) | 2021.06.29 |
반응형
250x250
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 허들
- 오블완
- 배프
- Hurdles
- Innovation&Hurdles
- 전류
- 티스토리챌린지
- Innovations&Hurdles
- 둎
- Video
- 전압
- DYOV
- 아두이노
- BSC
- image
- 치매방지
- 치매
- Decorator
- ServantClock
- arduino
- 빌리언트
- bilient
- Innovations
- 혁신
- 전압전류모니터링
- 심심풀이치매방지기
- 혁신과허들
- 절연형
- 심심풀이
- badp
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함