{"id":261,"date":"2019-01-13T15:31:35","date_gmt":"2019-01-13T06:31:35","guid":{"rendered":"http:\/\/lziuchfml.dip.jp\/blog\/?p=261"},"modified":"2019-01-20T11:16:07","modified_gmt":"2019-01-20T02:16:07","slug":"python%e3%81%a7%e7%94%bb%e5%83%8f%e3%82%92%e5%88%86%e5%89%b2%e3%81%99%e3%82%8b%e3%82%84%e3%81%a4","status":"publish","type":"post","link":"https:\/\/picman.dev\/blog\/2019\/01\/13\/python%e3%81%a7%e7%94%bb%e5%83%8f%e3%82%92%e5%88%86%e5%89%b2%e3%81%99%e3%82%8b%e3%82%84%e3%81%a4\/","title":{"rendered":"Python\u3067\u753b\u50cf\u3092\u5206\u5272\u3059\u308b\u3084\u3064"},"content":{"rendered":"\n<p>\u8868\u984c\u306e\u901a\u308a\u3001<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/lziuchfml.dip.jp\/blog\/wp-content\/uploads\/2019\/01\/cut-807x1024.png?resize=404%2C512\" alt=\"\" class=\"wp-image-262\" width=\"404\" height=\"512\" srcset=\"https:\/\/i0.wp.com\/picman.dev\/blog\/wp-content\/uploads\/2019\/01\/cut.png?resize=807%2C1024&amp;ssl=1 807w, https:\/\/i0.wp.com\/picman.dev\/blog\/wp-content\/uploads\/2019\/01\/cut.png?resize=236%2C300&amp;ssl=1 236w, https:\/\/i0.wp.com\/picman.dev\/blog\/wp-content\/uploads\/2019\/01\/cut.png?resize=768%2C974&amp;ssl=1 768w, https:\/\/i0.wp.com\/picman.dev\/blog\/wp-content\/uploads\/2019\/01\/cut.png?w=1600&amp;ssl=1 1600w\" sizes=\"auto, (max-width: 404px) 100vw, 404px\" \/><figcaption>\u5143\u753b\u50cf<\/figcaption><\/figure><\/div>\n\n\n\n<p>\u2191\u3053\u3093\u306a\u753b\u50cf\u3092\u3001\u3053\u3093\u306a\u3075\u3046\u306b\u5206\u5272\u2193<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"316\" src=\"https:\/\/i0.wp.com\/lziuchfml.dip.jp\/blog\/wp-content\/uploads\/2019\/01\/image-5-1024x316.png?resize=1024%2C316\" alt=\"\" class=\"wp-image-264\" srcset=\"https:\/\/i0.wp.com\/picman.dev\/blog\/wp-content\/uploads\/2019\/01\/image-5.png?resize=1024%2C316&amp;ssl=1 1024w, https:\/\/i0.wp.com\/picman.dev\/blog\/wp-content\/uploads\/2019\/01\/image-5.png?resize=300%2C93&amp;ssl=1 300w, https:\/\/i0.wp.com\/picman.dev\/blog\/wp-content\/uploads\/2019\/01\/image-5.png?resize=768%2C237&amp;ssl=1 768w, https:\/\/i0.wp.com\/picman.dev\/blog\/wp-content\/uploads\/2019\/01\/image-5.png?w=1739&amp;ssl=1 1739w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n\n\n\n<p>\u3059\u308b\u3084\u3064\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># -*- coding: utf-8 -*-\n\n# \u53c2\u8003 : https:\/\/qiita.com\/kino15\/items\/ece822ec20ad5e80e382\n\nfrom PIL import Image\nimport os\nimport sys\nimport math\n\n### \u5404\u5b9a\u6570\u306e\u8a2d\u5b9a\n# \u7e26\u65b9\u5411\u5206\u5272\u6570\nSPLIT_HEIGHT = 16\n# \u6a2a\u65b9\u5411\u5206\u5272\u6570\nSPLIT_WIDTH = 16\n# \u5206\u5272\u5143\u30d5\u30a1\u30a4\u30eb\u30d1\u30b9\nORIGINAL_FILE_PATH = \".\/cut.png\"\n# \u51fa\u529b\u30d5\u30a9\u30eb\u30c0\u540d\nOUTPUT_PATH = \"splitImage\"\n# \u30bc\u30ed\u57cb\u3081\u3059\u308b\u304b\uff1f\uff08\u3059\u308b\u306a\u3089True\uff09\nZFILL_FLAG = True\n\ndef ImgSplit(im,w,h):\n    # \u8aad\u307f\u8fbc\u3093\u3060\u753b\u50cf\u306e\u9ad8\u3055\u3068\u5e45\u3092\u6307\u5b9a\u5206\u5272\u6570\u3067\u5272\u308b\n    height = h \/ SPLIT_HEIGHT\n    width = w \/ SPLIT_WIDTH\n\n    # \u7e26\u306e\u5206\u5272\u679a\u6570\n    for h1 in range(SPLIT_HEIGHT):\n        # \u6a2a\u306e\u5206\u5272\u679a\u6570\n        for w1 in range(SPLIT_WIDTH):\n            w2 = w1 * width\n            h2 = h1 * height\n            print(w2, h2, width + w2, height + h2)\n            yield im.crop((w2, h2, width + w2, height + h2))\n\nif __name__ == '__main__':\n    # \u753b\u50cf\u306e\u8aad\u307f\u8fbc\u307f\n    im = Image.open(ORIGINAL_FILE_PATH)\n    w = im.size[0]\n    h = im.size[1]\n    length = math.log10(SPLIT_HEIGHT * SPLIT_WIDTH) + 1\n    os.makedirs(OUTPUT_PATH, exist_ok=True)\n    for number, ig in enumerate(ImgSplit(im,w,h), 1):\n        # \u51fa\u529b\n        if ZFILL_FLAG:\n            ig.save(OUTPUT_PATH + \"\/\" + str(number).zfill(int(length)) + \".PNG\", \"PNG\")\n        else:\n            ig.save(OUTPUT_PATH + \"\/\" + str(number) +\".PNG\", \"PNG\")\n<\/code><\/pre>\n\n\n\n<p>BoUoW\u306ePython 3.6.3\u306b\u3066\u52d5\u4f5c\u78ba\u8a8d\u6e08\u307f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8868\u984c\u306e\u901a\u308a\u3001 \u2191\u3053\u3093\u306a\u753b\u50cf\u3092\u3001\u3053\u3093\u306a\u3075\u3046\u306b\u5206\u5272\u2193 \u3059\u308b\u3084\u3064\u3067\u3059\u3002 B&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[43],"tags":[44,46,45],"class_list":["post-261","post","type-post","status-publish","format-standard","hentry","category-python","tag-python","tag-46","tag-45"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pauHYc-4d","_links":{"self":[{"href":"https:\/\/picman.dev\/blog\/wp-json\/wp\/v2\/posts\/261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/picman.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/picman.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/picman.dev\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/picman.dev\/blog\/wp-json\/wp\/v2\/comments?post=261"}],"version-history":[{"count":3,"href":"https:\/\/picman.dev\/blog\/wp-json\/wp\/v2\/posts\/261\/revisions"}],"predecessor-version":[{"id":272,"href":"https:\/\/picman.dev\/blog\/wp-json\/wp\/v2\/posts\/261\/revisions\/272"}],"wp:attachment":[{"href":"https:\/\/picman.dev\/blog\/wp-json\/wp\/v2\/media?parent=261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/picman.dev\/blog\/wp-json\/wp\/v2\/categories?post=261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/picman.dev\/blog\/wp-json\/wp\/v2\/tags?post=261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}