일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- PANDAS
- Tkinter
- 파이썬
- Kotlin
- numpy
- c#
- list
- string
- dataframe
- Redshift
- SQL
- array
- Excel
- Apache
- math
- gas
- matplotlib
- Python
- Github
- Mac
- PySpark
- Java
- Google Excel
- GIT
- django
- PostgreSQL
- Google Spreadsheet
- hive
- google apps script
- Today
- Total
목록PIL (4)
달나라 노트
PIL module을 이용해서 이미지 위에 텍스트를 넣어봅시다. 단계는 다음과 같습니다. 1. 배경이 검은 색의 이미지를 생성한 후 2. 이 이미지를 불러와 흰색의 글씨를 쓴다. 코드를 봅시다. import numpy as np import cv2 from PIL import Image, ImageDraw img_file = 'img_black.png' img_file_with_text = 'img_black_with_text.png' # create black img arr_black = np.zeros(shape=(1080, 1080, 3), dtype=int) cv2.imwrite(img_file, arr_black) # 검정색 image 생성 # write letter on img cls_img ..
matplotlib는 굉장히 재미있는 기능들을 제공하는데 그 중에선 image 파일을 읽어서 그래프로 나타내주는 기능을 제공합니다. 제가 이전에 먹었던 녹차빙수 사진을 한번 matplotlib를 이용해서 그래프 위에 나타내보겠습니다. import matplotlib.pyplot as plt import matplotlib.image as img img_test = img.imread('greentea_ice_flakes.png') plt.imshow(img_test) plt.show() directory 구조는 위와 같습니다. pyplot.py 파일에 위 예시코드가 적혀있으며 greentea_ice_flakes.png 파일이 바로 제가 먹었던 녹차빙수 사진입니다. - img_test = img.imrea..
Python을 이용해 image 파일을 pdf로 변환하는 방법을 알아봅시다. pip install PIL pip install Pillow 사용되는 라이브러리는 PIL 입니다. PIL이 간혹 설치가 제대로 되지 않는 경우가 있을 수 있는데 그럴 땐 Pillow 패키지를 설치합시다. (Pillow 패키지를 설치해도 PIL 라이브러리는 이용할 수 있습니다.) from PIL import Image img = Image.open(r'test/img_test_1.png') img_rgb = img.convert('RGB') img_rgb.save('test/pdf_test_1.pdf') 위 예시는 test directory에 있는 img_test_1.png라는 이미지파일을 test directory안에 pdf_..
image를 ASCII character를 이용한 그림으로 변환할 수 있습니다. 변환할 image인 apple.png는 다음과 같습니다. apple 로고를 변환해볼게요. import PIL.Image # list of ascii characters used when convert image to ascii text list_ascii_chars = ['@', '#', 'S', '%', '?', '*', '+', ';', ':', ',', '.'] # resize image according to a new width def resize_image(pil_obj_image, new_width): width, height = pil_obj_image.size # obj_image = image object ..