{"id":315,"date":"2021-08-16T14:55:00","date_gmt":"2021-08-16T14:55:00","guid":{"rendered":"https:\/\/262235.xyz\/?p=315"},"modified":"2021-08-16T14:55:00","modified_gmt":"2021-08-16T14:55:00","slug":"315","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2021\/08\/16\/315\/","title":{"rendered":"Python\u6279\u91cf\u7ed9\u56fe\u5e93\u6dfb\u52a0\u6c34\u5370-\u66f4\u65b0\u540e\u80fd\u968f\u673a\u56db\u89d2"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/08\/1100398926.jpg\" alt=\"png.jpg\" title=\"png.jpg\"><br \/>\u6211\u4eec\u5148\u51c6\u5907\u4e00\u5f20PNG\u56fe\u7247\uff0c\u5728PS\u91cc\u8c03\u6574\u4e0b\u5927\u5c0f\u548c\u900f\u660e\u5ea6\uff0c\u4f7f\u7528\u4e0b\u9762\u811a\u672c\u53ef\u4ee5\u628aPNG\u56fe\u53e0\u52a0\u5230\u4e00\u5f20JPG\u56fe\u4e0a\uff0c\u7136\u540e\u4fdd\u5b58\u56fe\u7247\u67e5\u770b\u6c34\u5370\u662f\u5426\u5408\u9002\u3002<\/p>\n<pre><code># JPG\u53e0\u52a0PNG\u900f\u660e\u56fe\u7247\nfrom PIL import Image, ImageDraw, ImageFont, ImageGrab\n\nmark = Image.open(\"262235.png\").convert('RGBA')\n\nim = Image.open(\"th.jpg\")\n\n# \u6c34\u5370\u7c98\u8d34\u5750\u6807: \u5de6\u4e0a\u89d2x,y,\u53f3\u4e0b\u89d2x,y\nbox = ( im.width - mark.width,  im.height -  mark.height   , im.width , im.height)\n\n# \u7c98\u8d34\u64cd\u4f5c,\u53ef\u7406\u89e3\u4e3a\u5f80 box \u4e2d\u653e\u4e1c\u897f\n# \u6ce8\u610f\u8fd9\u91cc paste \u51fd\u6570\u7684\u7b2c3\u4e2a\u53c2\u6570\uff0c\u662falpha\u901a\u9053\n# \u4f20\u5165\u542b\u6709alphat\u901a\u9053\u7684\u56fe\u7247\uff0c\u4f1a\u81ea\u52a8\u91c7\u7528\u8be5\u56fe\u7247\u7684alpha\u901a\u9053\n# \u7b80\u5355\u8bf4\uff0c\u5c31\u662fPNG\u900f\u660e\u4f1a\u751f\u6548\u3002\u5177\u4f53\u770b\u6587\u6863\nim.paste(mark, box , mark )\n\nim.save(\"test_web_high.jpg\", quality=\"web_high\")\n# im.show()<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/08\/2807849033.png\" alt=\"mark.png\" title=\"mark.png\"><br \/><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/08\/2159782172.jpg\" alt=\"11.jpg\" title=\"11.jpg\"><\/p>\n<h2>\u600e\u4e48\u80fd\u6279\u91cf\u5904\u7406\u5f88\u591a\u56fe\u7247\u6587\u4ef6\u80fd\uff0c\u5c31\u8981\u7528\u5230 <code>glob.glob<\/code> \u51fd\u6570\u4e86<\/h2>\n<p><code>glob.glob<\/code> \u51fd\u6570\u529f\u80fd\uff1a\u5339\u914d\u6240\u6709\u7684\u7b26\u5408\u6761\u4ef6\u7684\u6587\u4ef6\uff0c\u5e76\u5c06\u5176\u4ee5list\u7684\u5f62\u5f0f\u8fd4\u56de<\/p>\n<pre><code>import sys, glob\n\nfiles = []\nfor f in sys.argv[1:]:\n    files = files + glob.glob(f)\n\nfor f in files:\n    print(\"FontName: \" + f)<\/code><\/pre>\n<ul>\n<li>\n<p>\u6d4b\u8bd5\u547d\u4ee4\u8f93\u51fa\u6548\u679c<\/p>\n<pre><code>$ python3 test.py  *.jpg  E:\/flashair_sRGB\/*.jpg\nFontName:test_web_high.jpg\nFontName:th.jpg\nFontName:E:\/flashair_sRGBDSC_5007.JPG\n...\nFontName:E:\/flashair_sRGBDSC_5214.JPG<\/code><\/pre>\n<\/li>\n<\/ul>\n<h2>\u628a\u4e0a\u97622\u4e2a\u6d4b\u8bd5\u811a\u672c\u7ec4\u5408\u5230\u4e00\u8d77\uff0c\u6279\u91cf\u6dfb\u52a0\u6c34\u5370\u7684\u811a\u672c\u5c31\u5b8c\u6210\u4e86<\/h2>\n<pre><code># JPG\u53e0\u52a0PNG\u900f\u660e\u56fe\u7247\nfrom PIL import Image, ImageDraw, ImageFont, ImageGrab\nimport sys, glob\n\nfiles = []\nfor f in sys.argv[1:]:\n    files = files + glob.glob(f)\n\n# \u811a\u672c\u6307\u5b9a\u505a\u6c34\u5370\u7684PNG\u56fe\nmark = Image.open(\"262235.png\").convert('RGBA')\n\nfor f in files:\n    im = Image.open(f)\n\n    # \u6c34\u5370\u7c98\u8d34\u5750\u6807: \u5de6\u4e0a\u89d2x,y,\u53f3\u4e0b\u89d2x,y\n    box = ( im.width - mark.width,  im.height -  mark.height   , im.width , im.height)\n\n    # \u6ce8\u610f\u8fd9\u91cc paste \u51fd\u6570\u7684\u7b2c3\u4e2a\u53c2\u6570\uff0c\u662falpha\u901a\u9053\n    im.paste(mark, box , mark )\n\n    im.save(f, quality=\"web_high\")\n    print(\"FontName: \" + f + \"   ....OK\")<\/code><\/pre>\n<h2>Python\u6279\u91cf\u7ed9\u56fe\u5e93\u6dfb\u52a0\u6c34\u5370-\u66f4\u65b0\u540e\u80fd\u968f\u673a\u56db\u89d2<\/h2>\n<pre><code>#  \u8be6\u7ec6\u8bf4\u660e\u7f51\u5740  https:\/\/www.lyvba.com\/index.php\/archives\/315\/\n\n# JPG\u53e0\u52a0PNG\u900f\u660e\u56fe\u7247\nfrom PIL import Image, ImageDraw, ImageFont, ImageGrab\nimport sys, glob, random\n\ndef getbox(mark, im, n):\n    if n == 0:  # \u6c34\u5370\u5de6\u4e0a\n        box = (0, 0, mark.width, mark.height)\n    if n == 1:  # \u6c34\u5370\u5de6\u4e0b\n        box = (0, im.height - mark.height, mark.width, im.height)\n    if n == 2:  # \u6c34\u5370\u53f3\u4e0a\n        box = (im.width - mark.width, 0, im.width, mark.height)\n    if n == 3:  # \u6c34\u5370\u53f3\u4e0b\n        box = (im.width - mark.width, im.height - mark.height, im.width, im.height)\n    return box\n\nfiles = []\nfor f in sys.argv[1:]:\n    files = files + glob.glob(f)\n\n# \u811a\u672c\u6307\u5b9a\u505a\u6c34\u5370\u7684PNG\u56fe\nmark = Image.open(\"262235.png\").convert('RGBA')\n\nfor f in files:\n    im = Image.open(f)\n\n    # \u6c34\u5370\u7c98\u8d34\u5750\u6807: \u5de6\u4e0a\u89d2x,y,\u53f3\u4e0b\u89d2x,y\n    box = getbox(mark , im , random.randint(0, 1000) % 4)\n\n    # \u6ce8\u610f\u8fd9\u91cc paste \u51fd\u6570\u7684\u7b2c3\u4e2a\u53c2\u6570\uff0c\u662falpha\u901a\u9053\n    im.paste(mark, box, mark)\n\n    im.save(f, quality=\"web_high\")\n    print(\"FontName: \" + f + \"   ....OK\")\n<\/code><\/pre>\n<h2>\u5bf9\u4e00\u5f20\u56fe\u7247\uff0c\u591a\u6b21\u968f\u673a\u52a0\u6c34\u5370\uff0c\u80fd\u5206\u5e03\u5230\u56db\u89d2<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/s3.bmp.ovh\/imgs\/2021\/08\/719cd08a831ae6a0.jpg\" alt=\"\" title=\"\"><\/p>\n<h2>\u5904\u7406\u591a\u4e2a\u76ee\u5f55\u4e0b\u7684 JPEG \u6587\u4ef6<\/h2>\n<ul>\n<li>\n<p>\u5148\u7528 <code>ls -1<\/code> \u5f97\u5230\u76ee\u5f55\u8868\uff0c\u7136\u540e\u52a0\u4e0a <code>\/*.jpg  <\/code>\uff0c\u518d\u6309\u4e0b\u9762\u6837\u5f0f\u6574\u7406\u597d<\/p>\n<pre><code>python3 mark.py  \\r\nNo.101\/*.jpg  \\r\nNo.102\/*.jpg  \\r\nNo.103\/*.jpg  \\r\nNo.104\/*.jpg  \\r\nNo.105\/*.jpg  \\r\nNo.106\/*.jpg  \\r\nNo.107\/*.jpg  \\r\nNo.108\/*.jpg  \\r\nNo.109\/*.jpg  \\r\nNo.110\/*.jpg  \\r\nNo.111\/*.jpg  \\r\nNo.112\/*.jpg  \\r\nNo.113\/*.jpg  \\r\nNo.114\/*.jpg  \\r\nNo.115\/*.jpg  \\r\nNo.116\/*.jpg<\/code><\/pre>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/s3.bmp.ovh\/imgs\/2021\/08\/0b8904d7870f890d.jpg\" alt=\"\" title=\"\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u4eec\u5148\u51c6\u5907\u4e00\u5f20PNG\u56fe\u7247\uff0c\u5728PS\u91cc\u8c03\u6574\u4e0b\u5927\u5c0f\u548c\u900f\u660e\u5ea6\uff0c\u4f7f\u7528\u4e0b\u9762\u811a\u672c\u53ef\u4ee5\u628aPNG\u56fe\u53e0\u52a0\u5230\u4e00\u5f20JPG\u56fe\u4e0a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[45],"class_list":["post-315","post","type-post","status-publish","format-standard","hentry","category-default","tag-python"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=315"}],"version-history":[{"count":0,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/315\/revisions"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}