{"id":532,"date":"2014-08-11T12:00:20","date_gmt":"2014-08-11T03:00:20","guid":{"rendered":"http:\/\/www.sria.co.jp\/blog\/?p=532"},"modified":"2014-08-13T12:28:01","modified_gmt":"2014-08-13T03:28:01","slug":"to-output-characters-aligned-with-gd-library","status":"publish","type":"post","link":"https:\/\/www.sria.co.jp\/blog\/2014\/08\/to-output-characters-aligned-with-gd-library\/","title":{"rendered":"GD\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u6587\u5b57\u3092\u53f3\u5bc4\u305b\u51fa\u529b\u3059\u308b"},"content":{"rendered":"<p>\u521d\u3081\u307e\u3057\u3066\u3002PHP\uff08\u3068\u30ac\u30f3\u30c0\u30e0\uff09\u3092\u52c9\u5f37\u4e2d\u306e\u3001\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u5e84\u5b50\u3067\u3059\u3002<\/p>\n<p>PHP\u306eGD\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3063\u3066\u3044\u3066\u3001\u6587\u5b57\u3092\u53f3\u5bc4\u305b\u51fa\u529b\u3059\u308b\u65b9\u6cd5\u3067\u5c11\u3057\u60a9\u307f\u307e\u3057\u305f\u306e\u3067\u3001\u30d6\u30ed\u30b0\u30cd\u30bf\u306b\u3057\u3066\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p><!--more--><\/p>\n<p>&nbsp;<\/p>\n<h3>\u30c6\u30b9\u30c8\u74b0\u5883<\/h3>\n<p>\u30fbMAMP(php 5.5.10)<br \/>\n\u30fbchrome<br \/>\n\u30fbIPA\u30d5\u30a9\u30f3\u30c8\u30d5\u30a1\u30a4\u30eb<\/p>\n<p>&nbsp;<\/p>\n<h3>\u3084\u308a\u305f\u3044\u3053\u3068<\/h3>\n<p>\u4e0b\u56f3\u306e\u3088\u3046\u306b\u3001\u753b\u50cf\u306b\u8907\u6570\u884c\u306e\u4efb\u610f\u306e\u6587\u5b57\u5217\u3092\u51fa\u529b\u3057\u305f\u3044\u5834\u5408\u306b\u3001\u53f3\u5bc4\u305b\u3067\u63c3\u3048\u3066\u51fa\u529b\u3057\u305f\u3044\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u3064\u307e\u308a\u3001\u3053\u3046\u306a\u3063\u3066\u3057\u307e\u3046\u306e\u3092\u30fb\u30fb\u30fb<\/p>\n<div id=\"attachment_556\" style=\"width: 510px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2014\/08\/gd01.png\"><img aria-describedby=\"caption-attachment-556\" loading=\"lazy\" class=\"size-full wp-image-556\" src=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2014\/08\/gd01.png\" alt=\"\u3084\u3089\u308c\u308b\u6c17\u304c\u3057\u306a\u3044\" width=\"500\" height=\"300\" \/><\/a><p id=\"caption-attachment-556\" class=\"wp-caption-text\">\u521d\u4ee3\u30ac\u30f3\u30c0\u30e0\u306e\u7b2c\uff14\u8a71\u307e\u3067\u89b3\u307e\u3057\u305f\u304c\u3001\u30ac\u30f3\u30c0\u30e0\u304c\u3084\u3089\u308c\u308b\u6c17\u304c\u307e\u3063\u305f\u304f\u3057\u307e\u305b\u3093\u3002<\/p><\/div>\n<p>&nbsp;<\/p>\n<p>\u3053\u3046\u3057\u305f\u3044\uff01<\/p>\n<div id=\"attachment_557\" style=\"width: 510px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2014\/08\/gd02.png\"><img aria-describedby=\"caption-attachment-557\" loading=\"lazy\" class=\"size-full wp-image-557\" src=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2014\/08\/gd02.png\" alt=\"\u304c\u3093\u3070\u308c\u30b6\u30af\uff01\" width=\"500\" height=\"300\" \/><\/a><p id=\"caption-attachment-557\" class=\"wp-caption-text\">\u304c\u3093\u3070\u308c\u30b6\u30af\uff01<\/p><\/div>\n<p>&nbsp;<\/p>\n<h3>\u5bfe\u5fdc\u65b9\u6cd5<\/h3>\n<p>\u307e\u305a\u5de6\u5bc4\u305b\u30bd\u30fc\u30b9\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u3059\u3002<\/p>\n<pre class=\"lang:php decode:true\" title=\"index.php\">&lt;?PHP\r\n\t\/\/ \u753b\u50cf\u306e\u65b0\u898f\u4f5c\u6210\r\n\t$image = imagecreatetruecolor(500, 300);\r\n\t\r\n\t\/\/ \u30d5\u30a9\u30f3\u30c8\u30b5\u30a4\u30ba\r\n\t$fsize = 50;\r\n\t\r\n\t\/\/ \u30d5\u30a9\u30f3\u30c8\u89d2\u5ea6\r\n\t$fangle = 0;\r\n\t\r\n\t\/\/ \u30d5\u30a9\u30f3\u30c8\u30ab\u30e9\u30fc\r\n\t$fcolor = imagecolorallocate($image, 255, 255, 255);\r\n\t\r\n\t\/\/ \u4f7f\u7528\u30d5\u30a9\u30f3\u30c8\r\n\t$fpath = \".\/ipagp.ttf\";\r\n\t\r\n\t\/\/ X\u5ea7\u6a19\u30de\u30fc\u30b8\u30f3\r\n\t$margin = 10;\r\n\t\r\n\t\/\/ \u6587\u5b57\u51fa\u529b\r\n\t$textList = array(\"\u9023\u90a6\u306e\", \"\u30e2\u30d3\u30eb\u30b9\u30fc\u30c4\u306f\", \"\u5316\u3051\u7269\u304b\");\r\n\tfor ($i = 0; $i &lt; count($textList); $i++) {\r\n\t\t\r\n\t\t\/\/ \u753b\u50cf\u306e\u51fa\u529b\u4f4d\u7f6e\u3092\u8a08\u7b97\r\n\t\t$px = $margin;\r\n\t\t\r\n\t\timagettftext($image, $fsize, $fangle, $px, 75 + 100 * $i, $fcolor, $fpath, $textList[$i]);\r\n\t}\r\n\t\r\n\t\/\/ \u753b\u50cf\u8868\u793a\r\n\theader(\"Content-Type: image\/png\");\r\n\timagepng($image);\r\n\r\n\t\/\/ \u5f8c\u59cb\u672b\r\n\timagedestroy($image);\r\n?&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>\u6b8b\u5ff5\u306a\u304c\u3089\u6587\u5b57\u51fa\u529b\u95a2\u6570\u306eimagettftext\u306b\u306f\u3001\u53f3\u5bc4\u305b\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001<\/p>\n<p style=\"padding-left: 30px;\">1. \u3042\u3089\u304b\u3058\u3081\u51fa\u529b\u3059\u308b\u6587\u5b57\u5217\u306e\u9577\u3055\u3092\u8a08\u7b97\u3057\u3066\u304a\u304f<\/p>\n<p style=\"padding-left: 30px;\">2. \u53f3\u5bc4\u305b\u3067\u63c3\u3048\u305f\u3044\u4f4d\u7f6e\u304b\u3089\u3001\u8a08\u7b97\u3057\u305f\u9577\u3055\u3092\u5f15\u3044\u305fX\u5ea7\u6a19\u306b\u6587\u5b57\u3092\u51fa\u529b<\/p>\n<p>\u3068\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u53f3\u5bc4\u305b\u306b\u5bfe\u5fdc\u3057\u305f\u30bd\u30fc\u30b9\u306f\u4e0b\u8a18\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:php mark:25,28,31 decode:true\" title=\"index.php\">&lt;?PHP\r\n\t\/\/ \u753b\u50cf\u306e\u65b0\u898f\u4f5c\u6210\r\n\t$image = imagecreatetruecolor(500, 300);\r\n\t\r\n\t\/\/ \u30d5\u30a9\u30f3\u30c8\u30b5\u30a4\u30ba\r\n\t$fsize = 50;\r\n\t\r\n\t\/\/ \u30d5\u30a9\u30f3\u30c8\u89d2\u5ea6\r\n\t$fangle = 0;\r\n\t\r\n\t\/\/ \u30d5\u30a9\u30f3\u30c8\u30ab\u30e9\u30fc\r\n\t$fcolor = imagecolorallocate($image, 255, 255, 255);\r\n\t\r\n\t\/\/ \u4f7f\u7528\u30d5\u30a9\u30f3\u30c8\r\n\t$fpath = \".\/ipagp.ttf\";\r\n\t\r\n\t\/\/ X\u5ea7\u6a19\u30de\u30fc\u30b8\u30f3\r\n\t$margin = 10;\r\n\t\r\n\t\/\/ \u6587\u5b57\u51fa\u529b\r\n\t$textList = array(\"\u9023\u90a6\u306e\", \"\u30e2\u30d3\u30eb\u30b9\u30fc\u30c4\u306f\", \"\u5316\u3051\u7269\u304b\");\r\n\tfor ($i = 0; $i &lt; count($textList); $i++) {\r\n\t\t\r\n\t\t\/\/ \u53f3\u5bc4\u305b\r\n\t\t$dim = imagettfbbox($fsize, $fangle, $fpath, $textList[$i]);\r\n\t\t\r\n\t\t\/\/ \u5e45\u3092\u8a08\u7b97\r\n\t\t$textWidth = $dim[4] - $dim[6];\r\n\t\t\r\n\t\t\/\/ \u753b\u50cf\u306e\u51fa\u529b\u4f4d\u7f6e\u3092\u8a08\u7b97\r\n\t\t$px = 500 - $textWidth - $margin;\r\n\t\t\r\n\t\timagettftext($image, $fsize, $fangle, $px, 75 + 100 * $i, $fcolor, $fpath, $textList[$i]);\r\n\t}\r\n\t\r\n\t\/\/ \u753b\u50cf\u8868\u793a\r\n\theader(\"Content-Type: image\/png\");\r\n\timagepng($image);\r\n\r\n\t\/\/ \u5f8c\u59cb\u672b\r\n\timagedestroy($image);\r\n?&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>1.\u306e\u6587\u5b57\u5217\u306e\u9577\u3055\u306f\u3001<a href=\"http:\/\/php.net\/manual\/ja\/function.imagettfbbox.php\" target=\"_blank\">imagettfbbox\u95a2\u6570<\/a>\u3067\u6c42\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u623b\u308a\u5024\u304c\u30c6\u30ad\u30b9\u30c8\u51fa\u529b\u6642\u306e\u5de6\u4e0b\u3001\u53f3\u4e0b\u3001\u53f3\u4e0a\u3001\u5de6\u4e0a\u306e\u305d\u308c\u305e\u308c\u306eX\u5ea7\u6a19\u3068Y\u5ea7\u6a19\u304c\u914d\u5217\u3067\u53d6\u5f97\u3067\u304d\u308b\u306e\u3067\u3001\u305d\u306e\u5024\u304b\u3089\u5e45\u3092\u8a08\u7b97\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u30d7\u30ed\u30dd\u30fc\u30b7\u30e7\u30ca\u30eb\u30d5\u30a9\u30f3\u30c8\u306e\u5834\u5408\u3001\u4e0a\u8a18\u5bfe\u5fdc\u3092\u884c\u3063\u3066\u3082\u82e5\u5e72\u305a\u308c\u3066\u3044\u308b\u3088\u3046\u306b\u898b\u3048\u3066\u3057\u307e\u3046\u305f\u3081\u3001\u51fa\u529b\u3059\u308b\u6587\u5b57\u306b\u3088\u3063\u3066\u82e5\u5e72\u8abf\u6574\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u4ee5\u4e0a\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>C\/C++\u3067\u80b2\u3063\u3066\u304d\u305f\u79c1\u3068\u3057\u3066\u306f\u3001PHP\u306e\u69cb\u6587\u306f\u30b9\u30c3\u3068\u982d\u306b\u5165\u308b\u306e\u3067\u597d\u304d\u3067\u3059\u3002<\/p>\n<p>\u4eca\u5f8c\u3082PHP\uff08\u3068\u30ac\u30f3\u30c0\u30e0\uff09\u306e\u304a\u52c9\u5f37\u304c\u3093\u3070\u308a\u307e\u3059\uff01<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u521d\u3081\u307e\u3057\u3066\u3002PHP\uff08\u3068\u30ac\u30f3\u30c0\u30e0\uff09\u3092\u52c9\u5f37\u4e2d\u306e\u3001\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u5e84\u5b50\u3067\u3059\u3002 PHP\u306eGD\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3063\u3066\u3044\u3066\u3001\u6587\u5b57\u3092\u53f3\u5bc4\u305b\u51fa\u529b\u3059\u308b\u65b9\u6cd5\u3067\u5c11\u3057\u60a9\u307f\u307e\u3057\u305f\u306e\u3067\u3001\u30d6\u30ed\u30b0\u30cd\u30bf\u306b\u3057\u3066\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"author":6,"featured_media":237,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[14,8],"tags":[50,54],"_links":{"self":[{"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/posts\/532"}],"collection":[{"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/comments?post=532"}],"version-history":[{"count":13,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/posts\/532\/revisions"}],"predecessor-version":[{"id":586,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/posts\/532\/revisions\/586"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/media\/237"}],"wp:attachment":[{"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/media?parent=532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/categories?post=532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/tags?post=532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}