{"id":2687,"date":"2020-05-19T03:11:27","date_gmt":"2020-05-18T18:11:27","guid":{"rendered":"https:\/\/its-more.jp\/ja_jp\/?p=2687"},"modified":"2020-05-19T04:58:36","modified_gmt":"2020-05-18T19:58:36","slug":"go%e3%81%ab%e3%82%88%e3%82%8bpng%e7%94%9f%e6%88%90%ef%bc%882%ef%bc%89","status":"publish","type":"post","link":"https:\/\/its-more.jp\/ja_jp\/?p=2687","title":{"rendered":"go\u306b\u3088\u308bpng\u306e\u751f\u6210\uff08\u7d42\u4e86\uff09"},"content":{"rendered":"\n<p>\u3055\u3066\u3001png\u306e\u5bb9\u308c\u7269\u306f\u308f\u304b\u3063\u305f\u306e\u3067\u3001\u4e2d\u8eab\u3092\u8a70\u3081\u3066\u307f\u3088\u3046\u3002\u30a4\u30e1\u30fc\u30b8\u30c7\u30fc\u30bf\u3092\u8a70\u3081\u308b\u306b\u306f\u3001\u3001\u3001\u3069\u3046\u3082 zlib \u5f62\u5f0f\u3067\u306e\u5727\u7e2e\uff08deflate\uff09\u306f\u5fc5\u9808\u3089\u3057\u3044\u3002\u306a\u3093\u3067\u3060\u308d\u3046\u3002<\/p>\n\n\n\n<p>\u540c\u4e00\u30de\u30b7\u30f3\u306e\u4e2d\u3067\u63ee\u767a\u6027\u3067\u5c0f\u3055\u3081\u306e\u753b\u50cf\u3092\u98db\u3070\u3059\u3060\u3051\u306a\u306e\u3067\u3001\u5727\u7e2e\u30fb\u4f38\u9577\u306e\u30aa\u30fc\u30d0\u30d8\u30c3\u30c9\u3092\u907f\u3051\u305f\u3044\u306e\u306b\u3002\u30de\u30b7\u30f3\u5185\u306a\u3089\u697d\u52dd\u306710Gbps\u51fa\u308b\u306e\u306b\u3001Zlib\u304b\u307e\u305b\u305f\u3089\u9045\u304f\u306a\u308b\u3002\u305d\u3082\u305d\u3082CRC\u3082\u3044\u3089\u306a\u3044\u3002\u3042\u308c\u3082\u304b\u306a\u308a\u91cd\u3044\u3002100Mbps\u304f\u3089\u3044\u306b\u843d\u3061\u3066\u3057\u307e\u3046\u611f\u3058\u3060\u3002\u305f\u304b\u3060\u304b4GHz\u306eCPU\u3067\u51e6\u7406\u3057\u3066\u308b\u3093\u3060\u3057\u3002\u305d\u3046\u8a00\u3048\u3070\u3001zlib \u306e\u5727\u7e2e\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u3067\u3001\u5727\u7e2e\u7121\u3057\u3063\u3066\u3042\u3063\u305f\u3063\u3051\u304b\u2026<\/p>\n\n\n\n<p>\u307e\u3042\u3001\u305b\u3063\u304b\u304f go \u304cPNG\u7528\u306e\u30a8\u30f3\u30b3\u30fc\u30c0\u3092\u7528\u610f\u3057\u3066\u304f\u308c\u3066\u308b\u3093\u3060\u304b\u3089\u3001\u307e\u305a\u306f\u305d\u308c\u3092\u4f7f\u3063\u3066\u307f\u3088\u3046\u3002\u518d\u3073\u3000<a href=\"https:\/\/golang.org\/pkg\/image\/png\/\">Packege png<\/a> \u306e\u30da\u30fc\u30b8\u3092\u898b\u308b\u3002\u305f\u3076\u3093\u3053\u306e Encode\u3068\u3044\u3046\u95a2\u6570\u3060\u308d\u3046\u3002\u5f15\u6570\u306f\u3069\u3046\u306a\u3063\u3066\u3044\u308b\u306e\u304b\u3000\u2026\u3000\u300cimage.<a href=\"https:\/\/golang.org\/pkg\/image\/#Image\">Image<\/a>\u300d\u3002\u306a\u3093\u3060\u308d\u3046\u3001\u3053\u308c\u3002Rectangle \u2026\u3002\u2026\u3002\u2026\u3002\u3048\u30fc\u3063\u3001\u3064\u307e\u308a\u3053\u308c\u3067\u3053\u308c\u3067\u3054\u306b\u3087\u3054\u306b\u3087\u30a4\u30e1\u30fc\u30b8\u3092\u4f5c\u3063\u3066\u3084\u3063\u3066\u3001Package png \u306b\u6e21\u3057\u3066\u3084\u308b\u3068\u3001PNG \u5f62\u5f0f\u306b\u3057\u3066\u304f\u308c\u308b\u3063\u3066\u4e8b\uff1f\u3000\u305d\u3046\u306a\u3093\u3067\u3059\u304b\u3002<\/p>\n\n\n\n<p>\u306a\u30fc\u3093\u3060<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/its-more.jp\/ja_jp\/wp-content\/uploads\/2020\/05\/rofl-2.gif\" alt=\"\" class=\"wp-image-2693\" width=\"86\" height=\"86\"\/><\/figure><\/div>\n\n\n\n<p class=\"has-text-align-center has-large-font-size\">\u306a\u30fc\u3093\u3060\u3041\uff01<\/p>\n\n\n\n<p>\u307e\u3042\u3001\u305d\u3046\u3044\u3046\u3082\u306e\u304c\u7121\u3044\u65b9\u304c\u304a\u304b\u3057\u3044\u3068\u601d\u3063\u305f\u3002\u3067\u3082\u307e\u3042\u3044\u3044\u300110\u5e74\u306e\u6642\u306e\u6d41\u308c\u3092\u5b9f\u4f53\u9a13\u3057\u306a\u304c\u30891\u65e5\u3067\u98db\u3073\u8d8a\u3048\u3089\u308c\u305f\u304b\u3089\u3002PNG\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3082\u52c9\u5f37\u3067\u304d\u305f\u3057\u3001\u4f55\u304b\u306e\u5f79\u306b\u7acb\u3064\u304b\u3082\u77e5\u308c\u306a\u3044\u3002<\/p>\n\n\n\n<h2>png Package\u306b\u3088\u308b png \u306e\u751f\u6210<\/h2>\n\n\n\n<p>\u305d\u308c\u3067\u3001\u305d\u308c\u3063\u3066\u3069\u3046\u4f7f\u3046\u306e\u3063\u3066\u3001\u3053\u308c\u304c Encode \u306e <a href=\"https:\/\/golang.org\/pkg\/image\/png\/#example_Encode\">Example<\/a> \u3067\u3059\u304b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code small-code\"><code>package main\n\nimport (\n\t\"image\"\n\t\"image\/color\"\n\t\"image\/png\"\n\t\"log\"\n\t\"os\"\n)\n\nfunc main() {\n\tconst width, height = 256, 256\n\n\t\/\/ Create a colored image of the given width and height.\n\timg := image.NewNRGBA(image.Rect(0, 0, width, height))\n\n\tfor y := 0; y &lt; height; y++ {\n\t\tfor x := 0; x &lt; width; x++ {\n\t\t\timg.Set(x, y, color.NRGBA{\n\t\t\t\tR: uint8((x + y) &amp; 255),\n\t\t\t\tG: uint8((x + y) &lt;&lt; 1 &amp; 255),\n\t\t\t\tB: uint8((x + y) &lt;&lt; 2 &amp; 255),\n\t\t\t\tA: 255,\n\t\t\t})\n\t\t}\n\t}\n\n\tf, err := os.Create(\"image.png\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tif err := png.Encode(f, img); err != nil {\n\t\tf.Close()\n\t\tlog.Fatal(err)\n\t}\n\n\tif err := f.Close(); err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n<\/code><\/pre>\n\n\n\n<p>New \u3057\u3066 Set \u3057\u305f\u3089 Encode \u3057\u3066\u7d42\u4e86\u3067\u3059\u304b\u3002\u305d\u3046\u3067\u3059\u304b\u30fc\u3002\u3069\u308c\u3069\u308c\u3002go run go\u3002\u51fa\u6765\u305f\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" src=\"https:\/\/its-more.jp\/ja_jp\/wp-content\/uploads\/2020\/05\/image.png\" alt=\"\" class=\"wp-image-2702\" width=\"164\" height=\"164\" srcset=\"https:\/\/its-more.jp\/ja_jp\/wp-content\/uploads\/2020\/05\/image.png 256w, https:\/\/its-more.jp\/ja_jp\/wp-content\/uploads\/2020\/05\/image-150x150.png 150w, https:\/\/its-more.jp\/ja_jp\/wp-content\/uploads\/2020\/05\/image-100x100.png 100w\" sizes=\"(max-width: 164px) 100vw, 164px\" \/><\/figure><\/div>\n\n\n\n<p>\u30b9\u30c6\u30ad\u3002\u3044\u3084\u306f\u3084\u6975\u697d\u6975\u697d\u3002\u3044\u3044\u4e16\u306e\u4e2d\u306b\u306a\u3063\u305f\u3082\u306e\u305f\u308d\u3046\u3060\u306a\u30fc :-)\u3002\u3082\u3046\u9053\u5177\u306f\u5168\u3066\u63c3\u3063\u3066\u308b\u3063\u3066\u611f\u3058\u3002<\/p>\n\n\n\n<p>\u81ea\u5206\u3067\u4f5c\u3063\u305f\u306e\u3082\u3001\u9752\u6625\u306e\u601d\u3044\u51fa\u3068\u3057\u3066\u30a2\u30fc\u30ab\u30a4\u30d6\u3057\u3066\u304a\u3053\u3046\uff08\u7b11\uff09\u3002\u3053\u308c\u306f\u3053\u308c\u3067\u3001\u697d\u3057\u304b\u3063\u305f\u3002\u3084\u306f\u308a\u3001\u304c\u3063\u3061\u308a\u3057\u305f\u6709\u540d\u306a\u4ed5\u69d8\u66f8\u3092\u8aad\u307f\u306a\u304c\u3089\u5b9f\u88c5\u3059\u308b\u306e\u306f\u30ef\u30af\u30ef\u30af\u3059\u308b\u3002\u3057\u304b\u3057\u3001\u5358\u306b\u30d0\u30a4\u30c8\u5217\u3092\u76f4\u7dda\u7684\u306b\u30d0\u30c3\u30d5\u30a1\u306b\u66f8\u3044\u3066\u3044\u304f\u306e\u3092Go\u8a00\u8a9e\u3067\u52b9\u7387\u7684\u306b\u3084\u308b\u65b9\u6cd5\u304c\u307e\u3060\u308f\u304b\u3089\u306a\u3044\u3002\u307e\u3042\u3001string \u3058\u3083\u306a\u304f\u3066 byte \u3068\u3044\u3046\u306e\u3067\u3084\u308b\u3093\u3060\u308d\u3046\u2026<\/p>\n\n\n\n\/*<hr>\n&lt;base href=https:\/\/www.w3.org\/TR\/PNG\/>\n<style>pre.code{ padding-left:10px; font-size:10pt; font-family:\"Courier New\"; }\n<\/style><pre class=code id=code>\n\t2020-0518-03 pnggen\/0.0.3 (PNG generator) by ITS more :-)\n\tReference: <a href=https:\/\/www.w3.org\/TR\/PNG\/>PNG Ed.2 Spec.<\/a>\n<hr>*\/\n\npackage main\nimport (\n        \"os\"\n        \"fmt\"\n\t\"hash\/crc32\"\n)\nfunc myid() string {\n\treturn \"pnggen\/0.0.3 (PNG Generator)\"\n}\nfunc hton32b(hint int)(string){\n\tbuf := make([]byte, 4)\n\tbuf[0] = byte(hint >> 24)\n\tbuf[1] = byte(hint >> 16)\n\tbuf[2] = byte(hint >>  8)\n\tbuf[3] = byte(hint)\n\treturn string(buf)\n}\nfunc putNetInt32(file *os.File, hint int) int {\n        file.Write([]byte(hton32b(hint)))\n\treturn 4\n}\n\/\/<a href=#5Chunk-layout> 5.3 Chunk layout <\/a> Chunk := Length+Type+Data+CRC\nfunc putChunk(file *os.File, ctype string, cdata string) int {\n\tcrc := crc32.ChecksumIEEE([]byte(ctype+cdata))\t\/\/ heavy if large\n        olen := putNetInt32(file,len(cdata))\t\/\/ length of data\n        file.Write([]byte(ctype))\t\t\/\/ chunk type\n\tfile.Write([]byte(cdata))\t\t\/\/ chunk data\n\tolen += putNetInt32(file,int(crc))\t\/\/ CRC of type plus data\n\treturn olen + len(ctype) + len(cdata)\n}\nfunc pnggen() {\n        outfile := \"x3.png\"\n\tgenw := 64;\n\tgenh := 64;\n        fmt.Fprintf(os.Stderr,\"-- %s --\\n\",myid()) \n        file, _ := os.Create(outfile)\n        defer file.Close()\n        \n\t\/\/---- Signature -- <a href=#5PNG-file-signature> 5.2 PNG signagure <\/a>\n        PNGsignature := \"\\x89PNG\\r\\n\\x1A\\n\"\n        file.Write([]byte(PNGsignature))\n\tolen := len(PNGsignature)\n        \n\t\/\/---- IHDR -- <a href=#11IHDR> 11.2.2.2 IHDR Image header <\/a>\n        ihdr := hton32b(genw) \/\/ Width\n        ihdr += hton32b(genh) \/\/ Hight \n        ihdr += string(1) \/\/ Bit depth, 1 for monocrome\n        ihdr += string(0) \/\/ Color type, 0 for Grayscalse\n        ihdr += string(0) \/\/ Compression method, 0 for deflate\/inflate \n        ihdr += string(0) \/\/ Filter method, 0 for adaptive\n        ihdr += string(0) \/\/ Interlace method, 0 for no interlace\n\tolen += putChunk(file,\"IHDR\",ihdr)\n\n\t\/\/---- PLTE -- <a href=#11PLTE> 11.2.2.3 PLTE Pallete <\/a>\n\tolen += putChunk(file,\"PLTE\",\"\");\n\n\t\/\/---- IDAT -- <a href=#11IDAT> 11.2.2.4 IDAT Image data <\/a>\n\tolen += putChunk(file,\"IDAT\",\"\")\n\n\t\/\/---- IEND -- <a href=#11IEND> 11.2.2.5 IEND Image trailer <\/a>\n\tolen += putChunk(file,\"IEND\",\"\")\n\n        fmt.Fprintf(os.Stderr,\"-- created %s (%d x %d) %d bytes\\n\",\n\t\toutfile,genw,genh,olen) \n}\nfunc main() {\n\tpnggen()\n}\n\/\/ <\/pre><hr>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-file\"><a href=\"https:\/\/its-more.jp\/ja_jp\/wp-content\/uploads\/2020\/05\/go\u306b\u3088\u308bpng\u306e\u751f\u6210\uff08\u7d42\u4e86\uff09-\u2013-\u682a\u5f0f\u4f1a\u793e-ITS-more.pdf\">go\u306b\u3088\u308bpng\u306e\u751f\u6210\uff08\u7d42\u4e86\uff09-\u2013-\u682a\u5f0f\u4f1a\u793e-ITS-more<\/a><a href=\"https:\/\/its-more.jp\/ja_jp\/wp-content\/uploads\/2020\/05\/go\u306b\u3088\u308bpng\u306e\u751f\u6210\uff08\u7d42\u4e86\uff09-\u2013-\u682a\u5f0f\u4f1a\u793e-ITS-more.pdf\" class=\"wp-block-file__button\" download>\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9<\/a><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3001png\u306e\u5bb9\u308c\u7269\u306f\u308f\u304b\u3063\u305f\u306e\u3067\u3001\u4e2d\u8eab\u3092\u8a70\u3081\u3066\u307f\u3088\u3046\u3002\u30a4\u30e1\u30fc\u30b8\u30c7\u30fc\u30bf\u3092\u8a70\u3081\u308b\u306b\u306f\u3001\u3001\u3001\u3069\u3046\u3082 zlib \u5f62\u5f0f\u3067\u306e\u5727\u7e2e\uff08deflate\uff09\u306f\u5fc5\u9808\u3089\u3057\u3044\u3002\u306a\u3093\u3067\u3060\u308d\u3046\u3002 \u540c\u4e00\u30de\u30b7\u30f3\u306e\u4e2d\u3067\u63ee\u767a\u6027\u3067\u5c0f\u3055\u3081\u306e\u753b\u50cf\u3092\u98db\u3070\u3059\u3060\u3051\u306a\u306e\u3067 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/its-more.jp\/ja_jp\/?p=2687\" class=\"more-link\"><span class=\"screen-reader-text\">\"go\u306b\u3088\u308bpng\u306e\u751f\u6210\uff08\u7d42\u4e86\uff09\" \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/its-more.jp\/ja_jp\/index.php?rest_route=\/wp\/v2\/posts\/2687"}],"collection":[{"href":"https:\/\/its-more.jp\/ja_jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/its-more.jp\/ja_jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/its-more.jp\/ja_jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/its-more.jp\/ja_jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2687"}],"version-history":[{"count":52,"href":"https:\/\/its-more.jp\/ja_jp\/index.php?rest_route=\/wp\/v2\/posts\/2687\/revisions"}],"predecessor-version":[{"id":2750,"href":"https:\/\/its-more.jp\/ja_jp\/index.php?rest_route=\/wp\/v2\/posts\/2687\/revisions\/2750"}],"wp:attachment":[{"href":"https:\/\/its-more.jp\/ja_jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/its-more.jp\/ja_jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/its-more.jp\/ja_jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}