นี่คือไลบรารีที่ช่วยให้คุณสร้างภาพตัวอย่างจากแบบอักษรที่เลือกอย่างน้อยหนึ่งแบบ
เอกสารเต็มอยู่ที่นี่: readthedocs
หากคุณต้องการทดสอบแพ็คเกจก่อนติดตั้งให้ใช้การทดสอบ:
$ git clone https://github.com/MatteoGuadrini/fontpreview.git
$ cd fontpreview
$ python -m unittest test_fp.py ใช้ PYPI:
$ pip install --user fontpreviewหมายเหตุ : หากคุณต้องการใช้เครื่องมือบรรทัดคำสั่งคุณต้องติดตั้งไลบรารีทั่วทั้งระบบ:
pip install fontpreview
ตัวอย่างตัวอย่าง:
from fontpreview import FontPreview
fp = FontPreview ( '/tmp/noto.ttf' )
fp . save ( '/tmp/fp.png' )ตัวอย่างแบนเนอร์:
from fontpreview import FontBanner
fb = FontBanner ( '/tmp/noto.ttf' , 'landscape' , bg_color = ( 153 , 153 , 255 ), mode = 'fontname' )
fb . save ( '/tmp/fb.png' )ตัวอย่างโลโก้:
from fontpreview import FontLogo
fl = FontLogo ( '/tmp/noto.ttf' , 'Fp' )
fl . save ( '/tmp/fl.png' )ตัวอย่างผนังแบบอักษร:
from fontpreview import FontBanner , FontWall
# Define the various parts of wall
fb = FontBanner ( '/tmp/noto.ttf' , 'landscape' , mode = 'fontname' )
fb2 = FontBanner ( '/tmp/noto.ttf' , 'landscape' , mode = 'alpha' )
fb3 = FontBanner ( '/tmp/noto.ttf' , 'landscape' , mode = 'letter' )
fb4 = FontBanner ( '/tmp/noto.ttf' , 'landscape' , mode = 'paragraph' )
fw = FontWall ([ fb , fb2 , fb3 , fb4 ])
fw . save ( '/tmp/fw.png' )ตัวอย่างหน้าอักษร:
from fontpreview import FontPage , FontBanner
# Define the various parts of page
header = FontBanner ( '/tmp/noto.ttf' , 'landscape' , mode = 'fontname' )
body = FontBanner ( '/tmp/noto.ttf' , 'landscape' , mode = 'paragraph' )
footer = FontBanner ( '/tmp/noto.ttf' , 'landscape' , mode = 'letter' )
# Create FontPage object
fpage = FontPage ()
fpage . set_header ( header )
fpage . set_body ( body )
fpage . set_footer ( footer )
# Design all parts
fpage . draw ()
fpage . save ( '/tmp/fpage.png' )หน้าตัวอักษรที่มีตัวอย่างแม่แบบ:
from fontpreview import FontPage , FontPageTemplate , FontBanner
# Define the various parts of page
header = FontBanner ( '/tmp/noto.ttf' , 'landscape' , mode = 'fontname' )
body = FontBanner ( '/tmp/noto.ttf' , 'landscape' , mode = 'paragraph' )
footer = FontBanner ( '/tmp/noto.ttf' , 'landscape' , mode = 'letter' )
# Create font page template
template = FontPageTemplate ( 3508 )
template . set_body ( 170 , 1 , 'lcenter' )
template . set_footer ( 100 , 4 , 'lcenter' )
# Create FontPage object
fpage = FontPage ( template = template )
fpage . set_header ( header )
fpage . set_body ( body )
fpage . set_footer ( footer )
# Design all parts
fpage . draw ()
fpage . save ( '/tmp/fpage_template.png' )ตัวอย่างของหนังสือเล่มเล็ก:
from fontpreview import FontPage , FontBanner , FontBooklet
# Define the various parts of page
header = FontBanner ( '/tmp/noto.ttf' , 'landscape' , mode = 'fontname' )
body = FontBanner ( '/tmp/noto.ttf' , 'landscape' , mode = 'paragraph' )
footer = FontBanner ( '/tmp/noto.ttf' , 'landscape' , mode = 'letter' )
# Create FontPage object
fpage1 = FontPage ( header = header , body = body , footer = footer )
fpage2 = FontPage ( header = header , body = body , footer = footer )
# Design all parts
fpage1 . draw ()
fpage2 . draw ()
# Create book
book = FontBooklet ( fpage1 , fpage2 )
book . save ( '/tmp/noto_book/' ) # save page1.png, page2.png in /tmp/noto_book/ folder ด้านล่างเป็นตัวอย่างของตัวอย่างต่างๆของแบบอักษร "FIRA Code ปกติ" มันเตือนคุณถึงอะไร? รหัส fira ต้นฉบับ
# FIRA CODE WALL
from fontpreview import FontBanner , FontWall
fira_code = '/tmp/firacode.ttf'
# RGB group = ('background', 'FIRA COD color', 'Ligature color', 'E color background')
colors_group = [
( 'black' , ( 0 , 143 , 0 ), ( 0 , 236 , 236 ), ( 255 , 0 , 255 )),
( 'black' , ( 166 , 47 , 123 ), ( 81 , 208 , 93 ), ( 11 , 179 , 248 )),
(( 13 , 21 , 43 ), ( 112 , 204 , 84 ), ( 226 , 110 , 34 ), ( 223 , 245 , 90 )),
(( 43 , 6 , 42 ), ( 136 , 126 , 135 ), ( 4 , 150 , 153 ), ( 147 , 103 , 145 )),
(( 39 , 57 , 85 ), ( 255 , 241 , 208 ), ( 208 , 84 , 0 ), ( 209 , 215 , 227 )),
(( 31 , 63 , 89 ), ( 248 , 248 , 242 ), ( 230 , 219 , 117 ), ( 166 , 226 , 51 )),
(( 1 , 47 , 80 ), ( 224 , 202 , 52 ), ( 73 , 217 , 38 ), ( 255 , 125 , 158 )),
(( 0 , 0 , 170 ), ( 75 , 224 , 245 ), ( 255 , 255 , 85 ), ( 0 , 170 , 170 )),
( 'white' , 'black' , 'black' , 'black' ),
(( 247 , 247 , 247 ), ( 167 , 29 , 93 ), ( 121 , 93 , 163 ), ( 0 , 134 , 179 )),
(( 239 , 240 , 243 ), ( 15 , 131 , 207 ), ( 208 , 84 , 0 ), ( 105 , 40 , 122 )),
(( 239 , 231 , 212 ), ( 218 , 116 , 53 ), ( 0 , 142 , 212 ), ( 186 , 136 , 0 )),
(( 39 , 40 , 34 ), ( 132 , 214 , 45 ), ( 249 , 39 , 114 ), ( 174 , 129 , 255 )),
(( 43 , 48 , 59 ), ( 180 , 142 , 173 ), ( 143 , 161 , 179 ), ( 152 , 190 , 140 )),
(( 32 , 32 , 32 ), ( 171 , 130 , 84 ), ( 160 , 171 , 127 ), ( 216 , 127 , 98 )),
(( 0 , 43 , 54 ), ( 0 , 160 , 153 ), ( 126 , 143 , 3 ), ( 218 , 66 , 130 ))
]
banners = []
# Create banners
for colors in colors_group :
# Create a FontBanner objects
fb = FontBanner ( fira_code , ( 413 , 240 ))
liga = FontBanner ( fira_code , ( 413 , 240 ))
E = FontBanner ( fira_code , ( 40 , 70 ))
# Set background colors
fb . bg_color = liga . bg_color = colors [ 0 ]
E . bg_color = colors [ 3 ]
# Set foreground colors
fb . fg_color = colors [ 1 ]
liga . fg_color = colors [ 2 ]
E . fg_color = colors [ 0 ]
# Set text
fb . font_text = 'FIRA COD'
liga . font_text = "!=->>++:="
E . font_text = 'E'
# Set text position
E . set_text_position ( 'ltop' )
fb . set_text_position (( 25 , 60 ))
liga . set_text_position ( 'top' )
# Adding image on fb
fb . add_image ( liga , ( 0 , 122 ))
fb . add_image ( E , ( 339 , 60 ))
# Add to list of banners
banners . append ( fb )
# Create a wall
fw = FontWall ( banners , max_tile = 4 )
fw . save ( '/tmp/fira_code.png' ) นอกเหนือจากแพ็คเกจแล้วเครื่องมือบรรทัดคำสั่งที่ใช้แพ็คเกจ Python นี้ได้รับการติดตั้ง คลาสที่ใช้สำหรับตัวอย่างบรรทัดคำสั่งคือ FontPreview สำหรับตัวเลือกทั้งหมดของเครื่องมือนี้ให้ดูเอกสารมิฉะนั้นเรียกใช้ fp -h
$ fp /tmp/noto.ttfคำสั่งนี้บันทึก fontpreview.png ในไดเรกทอรีปัจจุบัน
FontPreview เป็นโครงการโอเพ่นซอร์ส มีส่วนร่วมใด ๆ ยินดีต้อนรับ
ขอบคุณมาก
สำหรับการบริจาคกดสิ่งนี้
สำหรับฉัน
สำหรับ Telethon
มูลนิธิ Telethon เป็นองค์กรที่ไม่แสวงหาผลกำไรที่ได้รับการยอมรับจากกระทรวงมหาวิทยาลัยและการวิจัยทางวิทยาศาสตร์และเทคโนโลยี พวกเขาเกิดในปี 2533 เพื่อตอบสนองต่อการอุทธรณ์ของผู้ป่วยที่ทุกข์ทรมานจากโรคที่หายาก มาวันนี้เรามีการจัดระเบียบเพื่อฟังพวกเขาและคำตอบทุกวันตลอดทั้งปี
นำอนาคตมาใช้
ขอบคุณ Mark Lutz สำหรับการเขียนหนังสือ Python และ Programming Python ที่ประกอบขึ้นเป็นมูลนิธิ Python ของฉัน
ขอบคุณ Kenneth Reitz และ Tanya Schlusser สำหรับการเขียน คู่มือ Hitchhiker's Guide to Python Books
ขอบคุณ Dane Hillard สำหรับการเขียน การปฏิบัติของหนังสือ Python Pro
ขอขอบคุณเป็นพิเศษไปที่ภรรยาของฉันที่เข้าใจเวลาขาดงานสำหรับการพัฒนานี้ ขอบคุณลูก ๆ ของฉันสำหรับแรงบันดาลใจในชีวิตประจำวันที่พวกเขาให้ฉันและทำให้ฉันรู้ว่าชีวิตจะต้องเรียบง่าย
ขอบคุณ Python!