国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python如何將圖片轉換為字符圖片

2020-01-04 15:28:52
字體:
來源:轉載
供稿:網友

簡介

一個簡單的python程序,將圖片轉換為字符圖片。
(為了簡便,很多參數寫死了,自己看著改吧。 (←∀←))

正文

原圖(侵刪)

python,圖片轉換,字符圖片,python圖片轉換,python圖片字符轉換

結果圖

python,圖片轉換,字符圖片,python圖片轉換,python圖片字符轉換

源碼

[更多細節]——>戳這里

#-*- coding: UTF-8 -*- from PIL import Image from PIL import ImageDraw from PIL import ImageFontimport matplotlib.pyplot as pltimport numpy as npimport timedef happyNewYear(srd_img_file_path, dst_img_file_path = None, scale = 2, sample_step = 3): start_time = int(time.time()) #讀取圖片信息 old_img = Image.open(srd_img_file_path) pix = old_img.load() width = old_img.size[0] height = old_img.size[1] print ("width:%d, height:%d" % (width, height)) #創建新圖片 canvas = np.ndarray((height*scale, width*scale, 3), np.uint8) canvas[:, :, :] = 255 new_image = Image.fromarray(canvas) draw = ImageDraw.Draw(new_image) #創建繪制對象 font = ImageFont.truetype("consola.ttf", 10, encoding="unic") char_table = list('happy new year ') # font = ImageFont.truetype('simsun.ttc', 10) # char_table = list(u'新年快樂') #開始繪制 pix_count = 0 table_len = len(char_table) for y in range(height):  for x in range(width):   if x % sample_step == 0 and y % sample_step == 0:    draw.text((x*scale, y*scale), char_table[pix_count % table_len], pix[x, y], font)    pix_count += 1 # 保存 if dst_img_file_path is not None:  new_image.save(dst_img_file_path) print("used time : %d second, pix_count : %d" % ((int(time.time()) - start_time), pix_count)) print(pix_count) new_image.show()happyNewYear("input.jpg", "output.jpg")

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到python教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新化县| 盐源县| 阿合奇县| 含山县| 长宁县| 阜康市| 社会| 稻城县| 科尔| 安国市| 乌海市| 茌平县| 呼玛县| 靖安县| 肥城市| 昭平县| 开平市| 福安市| 吉水县| 都安| 益阳市| 稷山县| 乐山市| 太湖县| 湾仔区| 永泰县| 旌德县| 扬中市| 会同县| 乐陵市| 霍邱县| 深泽县| 武义县| 德惠市| 大连市| 永善县| 宜宾县| 津市市| 锡林浩特市| 仁化县| 临湘市|