{"id":150,"date":"2016-10-24T04:55:08","date_gmt":"2016-10-23T19:55:08","guid":{"rendered":"http:\/\/www.dogrow.net\/php\/?p=150"},"modified":"2023-08-09T13:46:02","modified_gmt":"2023-08-09T04:46:02","slug":"blog12","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/php\/blog12\/","title":{"rendered":"(12) GD\u3067\u4f5c\u6210\u3057\u305f\u753b\u50cf\u3092\u30d5\u30a1\u30a4\u30eb\u4fdd\u5b58"},"content":{"rendered":"<h1 class=my_h1>\u3084\u3063\u3066\u307f\u305f\u3044\u3053\u3068<\/h1>\n<p>\u4ee5\u4e0b\u306e\u6295\u7a3f\u8a18\u4e8b\u3067\u306f\u3001GD\u3067\u4f5c\u6210\u3057\u305f\u753b\u50cf\u3092HTTP\u7d4c\u7531\u3067\u51fa\u529b\u3057\u3066\u3044\u305f\u3002<br \/>\n<a href=\"http:\/\/www.dogrow.net\/php\/archives\/116\">\u300c(9) GD\u3067\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u753b\u50cf\u3092\u767d\u9ed2\u753b\u50cf\u306b\u5909\u63db\u300d<\/a><br \/>\n<a href=\"http:\/\/www.dogrow.net\/php\/archives\/130\">\u300c(10) GD\u3067\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u753b\u50cf\u3092\u62e1\u5927\u30fb\u7e2e\u5c0f\u300d<\/a><br \/>\n<a href=\"http:\/\/www.dogrow.net\/php\/archives\/132\">\u300c(11) GD\u3067\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u753b\u50cf\u3092\u5207\u308a\u629c\u304d\u300d<\/a><\/p>\n<p>\u4eca\u56de\u306fGD\u3067\u4f5c\u6210\u3057\u305f\u753b\u50cf\u3092\u3001\u30b5\u30fc\u30d0\u30fc\u4e0a\u3067\u753b\u50cf\u30d5\u30a1\u30a4\u30eb\u3068\u3057\u3066\u4fdd\u5b58\u3059\u308b\u3002<br \/>\n\u3000<br \/>\n\u5b9f\u884c\u30b5\u30f3\u30d7\u30eb\u306f\u3053\u3061\u3089\u3067\u3059\u3002<br \/>\n<a href=\"http:\/\/www.dogrow.net\/php\/sample\/00012\/\" target=\"_blank\" rel=\"noopener\">http:\/\/www.dogrow.net\/php\/sample\/00012\/<\/a><\/p>\n<h1 class=my_h>\u30d7\u30ed\u30b0\u30e9\u30e0\u4f5c\u6210<\/h1>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u4ed5\u69d8\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<br \/>\n\u30fb\u753b\u50cf\u3092\u4f5c\u6210\u3059\u308b\u307e\u3067\u306e\u52d5\u4f5c\u306f <a href=\"http:\/\/www.dogrow.net\/php\/archives\/116\">\u300c(9) GD\u3067\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u753b\u50cf\u3092\u767d\u9ed2\u753b\u50cf\u306b\u5909\u63db\u300d<\/a> \u3068\u540c\u3058\u3068\u3059\u308b\u3002<br \/>\n\u30fb\u4f5c\u6210\u3057\u305f\u753b\u50cf\u3092\u30b5\u30fc\u30d0\u30fc\u4e0a\u306b\u30d5\u30a1\u30a4\u30eb\u51fa\u529b\u3057\u3001\u3053\u308c\u3092WEB\u30d6\u30e9\u30a6\u30b6\u4e0a\u3067\u8868\u793a\u3059\u308b\u3002<\/p>\n<h3 class=my_h>index.php<\/h3>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;HTML&gt;\r\n&lt;HEAD&gt;\r\n&lt;META CHARSET=&quot;UTF-8&quot; \/&gt;\r\n&lt;TITLE&gt;\u30b5\u30f3\u30d7\u30eb&lt;\/TITLE&gt;\r\n&lt;\/HEAD&gt;\r\n&lt;\/BODY&gt;\r\n\r\n&lt;?php\r\n  require_once(&quot;img_change.php&quot;);\r\n  \/\/ \u753b\u50cf\u5909\u63db\u51e6\u7406\u8981\u6c42\uff1f\r\n  if(isset($_POST&#x5B;'exec'])){\r\n    try{\r\n      if(is_uploaded_file($_FILES&#x5B;'upfile']&#x5B;'tmp_name'])){\r\n        \/\/ \u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3055\u308c\u305f\u753b\u50cf\u3092\u4fdd\u5b58\r\n        move_uploaded_file($_FILES&#x5B;'upfile']&#x5B;'tmp_name'], 'tmp.img');\r\n        \/\/ \u753b\u50cf\u5909\u63db\uff06\u8868\u793a\r\n        $new_img = &quot;.\/new.&quot;;\r\n        convert_img_to_file( 'tmp.img', $new_img );\r\n        echo &quot;&lt;img src=\\&quot;{$new_img}\\&quot;&gt;&quot;;\r\n      }\r\n    }catch(Exception $e){\r\n      echo &quot;&#x5B;&quot;.__LINE__.&quot;] Caught exception: &quot;.$e-&gt;getMessage();\r\n    }\r\n  }\r\n?&gt;\r\n\r\n&lt;hr \/&gt;\r\n&lt;form enctype=&quot;multipart\/form-data&quot; action=&quot;.\/&quot; method=&quot;post&quot;&gt;\r\n&lt;input type=&quot;file&quot; name=&quot;upfile&quot;&gt;&lt;br \/&gt;\r\n&lt;input name=&quot;exec&quot; type=&quot;submit&quot; value=&quot;JPEG,PNG\u753b\u50cf\u3092\u30b0\u30ec\u30fc\u30b9\u30b1\u30fc\u30eb\u753b\u50cf\u306b\u5909\u63db\u3057\u307e\u3059\u3002(\u4e00\u8fba1000\u30d4\u30af\u30bb\u30eb\u4ee5\u4e0b)&quot;&gt;\r\n&lt;\/form&gt;\r\n\r\n&lt;\/BODY&gt;\r\n&lt;\/HTML&gt;\r\n<\/pre>\n<h3 class=my_h>img_change.php<\/h3>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n\/\/ \u753b\u50cf\u5909\u63db\uff06\u51fa\u529b\r\nfunction convert_img_to_file( $fpath_in, &amp;$fpath_out ){\r\n  \/\/ \u753b\u50cf\u60c5\u5831\u3092\u53d6\u5f97\r\n  $ary_info = getimagesize( $fpath_in );\r\n  if($ary_info === FALSE){\r\n    goto tagEND;\r\n  }\r\n  if(($ary_info&#x5B;0] &gt; 1000) || ($ary_info&#x5B;1] &gt; 1000)){\r\n    goto tagEND;\r\n  }\r\n  $image_type = $ary_info&#x5B;2];\r\n  \/\/ \u753b\u50cf\u51e6\u7406\u3092\u9078\u629e\r\n  $func_create  = NULL;\r\n  $func_output = NULL;\r\n  switch( $image_type ){\r\n  case IMAGETYPE_JPEG:\r\n    $func_create = &quot;imagecreatefromjpeg&quot;;\r\n    $func_output = &quot;imagejpeg&quot;;\r\n    break;\r\n  case IMAGETYPE_PNG:\r\n    $func_create = &quot;imagecreatefrompng&quot;;\r\n    $func_output = &quot;imagepng&quot;;\r\n    break;\r\n  default:\r\n    break;\r\n  }\r\n  if($func_create === NULL){\r\n    goto tagEND;\r\n  }\r\n  \/\/ \u30b0\u30ec\u30fc\u30b9\u30b1\u30fc\u30eb\u753b\u50cf\u306b\u5909\u63db\r\n  $im_in = $func_create( $fpath_in );\r\n  conv_img_grayscale( $im_in, $im_out );\r\n  \/\/ \u30d5\u30a1\u30a4\u30eb\u51fa\u529b\r\n  $fpath_out .= image_type_to_extension($image_type);\r\n  $func_output( $im_out, $fpath_out);\r\n\r\n  imagedestroy( $im_in );\r\n  imagedestroy( $im_out );\r\ntagEND:\r\n}\r\n\/\/ \u5165\u529b\u753b\u50cf\u3092\u30b0\u30ec\u30fc\u30b9\u30b1\u30fc\u30eb\u753b\u50cf\u306b\u5909\u63db\r\nfunction conv_img_grayscale( $im_in, &amp;$im_out ){\r\n  $img_w = imageSX($im_in);\r\n  $img_h = imageSY($im_in);\r\n  for($y = 0 ; $y &lt; $img_h ; $y++){\r\n    for($x = 0 ; $x &lt;$img_w ; $x++){\r\n      \/\/ \u753b\u7d20\u5024\u3092\u53d6\u5f97\r\n      $cRGB = imagecolorat($im_in, $x, $y);\r\n      $cR = ($cRGB &gt;&gt; 16) &amp; 0xFF;\r\n      $cG = ($cRGB &gt;&gt; 8)  &amp; 0xFF;\r\n      $cB =  $cRGB &amp; 0xFF;\r\n      $g  = round(($cR + $cG + $cB) \/ 3);\r\n      \/\/ \u753b\u7d20\u5024\u3092\u4f5c\u6210\r\n      $gR = $g &lt;&lt; 16;\r\n      $gG = $g &lt;&lt; 8;\r\n      $gB = $g;\r\n      $gRGB = $gR | $gG | $gB;\r\n      imagesetpixel($im_in, $x, $y, $gRGB);\r\n      imagecolorallocate($im_in, $g, $g, $g);\r\n    }\r\n  }\r\n  \/\/ \u4f5c\u6210\u3057\u305f\u30b0\u30ec\u30fc\u30b9\u30b1\u30fc\u30eb\u753b\u50cf\u3092\u51fa\u529b\r\n  $im_out = imagecreatetruecolor($img_w, $img_h);\r\n  imagecopy($im_out, $im_in, 0, 0, 0, 0, $img_w, $img_h);\r\n}\r\n?&gt;\r\n<\/pre>\n<p>\u3000<br \/>\n\u5b9f\u884c\u30b5\u30f3\u30d7\u30eb\u306f\u3053\u3061\u3089\u3067\u3059\u3002<br \/>\n<a href=\"http:\/\/www.dogrow.net\/php\/sample\/00012\/\" target=\"_blank\" rel=\"noopener\">http:\/\/www.dogrow.net\/php\/sample\/00012\/<\/a><\/p>\n<hr class=my_hr_bottom>\n","protected":false},"excerpt":{"rendered":"<p>\u3084\u3063\u3066\u307f\u305f\u3044\u3053\u3068 \u4ee5\u4e0b\u306e\u6295\u7a3f\u8a18\u4e8b\u3067\u306f\u3001GD\u3067\u4f5c\u6210\u3057\u305f\u753b\u50cf\u3092HTTP\u7d4c\u7531\u3067\u51fa\u529b\u3057\u3066\u3044\u305f\u3002 \u300c(9) GD\u3067\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u753b\u50cf\u3092\u767d\u9ed2\u753b\u50cf\u306b\u5909\u63db\u300d \u300c(10) GD\u3067\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u753b\u50cf\u3092\u62e1\u5927\u30fb\u7e2e\u5c0f\u300d \u300c(11) GD\u3067\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/php\/blog12\/\">\u7d9a\u304d\u3092\u8aad\u3080 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,5,2],"tags":[],"class_list":["post-150","post","type-post","status-publish","format-standard","hentry","category-gd","category-5","category-2"],"views":3302,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts\/150","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/comments?post=150"}],"version-history":[{"count":29,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts\/150\/revisions"}],"predecessor-version":[{"id":2064,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts\/150\/revisions\/2064"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/media?parent=150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/categories?post=150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/tags?post=150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}