{"id":130,"date":"2016-10-24T03:37:52","date_gmt":"2016-10-23T18:37:52","guid":{"rendered":"http:\/\/www.dogrow.net\/php\/?p=130"},"modified":"2017-09-01T17:14:57","modified_gmt":"2017-09-01T08:14:57","slug":"blog10","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/php\/blog10\/","title":{"rendered":"(10) GD\u3067\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u753b\u50cf\u3092\u62e1\u5927\u30fb\u7e2e\u5c0f"},"content":{"rendered":"<h1 class=my_h>\u3084\u3063\u3066\u307f\u305f\u3044\u3053\u3068<\/h1>\n<p>\u4efb\u610f\u306eJPEG\u753b\u50cf\u30d5\u30a1\u30a4\u30eb\u3092WEB\u30d6\u30e9\u30a6\u30b6\u304b\u3089\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u3001\u6307\u5b9a\u30b5\u30a4\u30ba\u306b\u62e1\u5927\u30fb\u7e2e\u5c0f\u3057\u3066WEB\u30d6\u30e9\u30a6\u30b6\u306b\u8868\u793a\u3059\u308b\u3002<br \/>\nImageMagick\u3067\u306f\u306a\u304f GD\u3092\u4f7f\u7528\u3059\u308b\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/www.dogrow.net\/php\/wp-content\/uploads\/2016\/10\/sample_org.jpg\" alt=\"sample_org\" width=\"280\" height=\"209\" class=\"alignnone size-full wp-image-137\" \/><br \/>\n\u3000\u2193<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/\/www.dogrow.net\/php\/wp-content\/uploads\/2016\/10\/sample_mini.jpg\" alt=\"sample_mini\" width=\"150\" height=\"111\" class=\"alignnone size-full wp-image-136\" \/><br \/>\n\u3000<br \/>\n\u5b9f\u884c\u30b5\u30f3\u30d7\u30eb\u306f\u3053\u3061\u3089\u3067\u3059\u3002<br \/>\n<a href=\"\/\/www.dogrow.net\/php\/sample\/00010\/\" target=\"_blank\">\/\/www.dogrow.net\/php\/sample\/00010\/<\/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\u5909\u63db\u53ef\u80fd\u306a\u753b\u50cf\u5f62\u5f0f\u306f JPEG, PNG, GIF\u306e3\u7a2e\u985e\u3068\u3059\u308b\u3002<br \/>\n\u30fb\u5165\u529b\u753b\u50cf\u306f\u4e00\u8fba\u304c20\uff5e1000\u30d4\u30af\u30bb\u30eb\u306e\u753b\u50cf\u3092\u51e6\u7406\u5bfe\u8c61\u3068\u3059\u308b\u3002<br \/>\n\u30fb\u51fa\u529b\u753b\u50cf\u30b5\u30a4\u30ba\u306f\u4e00\u8fba\u304c20\uff5e1000\u30d4\u30af\u30bb\u30eb\u306e\u7bc4\u56f2\u3067\u6307\u5b9a\u53ef\u80fd\u3068\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&lt;?php\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        echo &quot;&lt;img src=\\&quot;img_resize.php?fpath=tmp.img&amp;w=&quot;.$_POST&#x5B;'w'].&quot;\\&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&lt;hr \/&gt;\r\n&lt;form enctype=&quot;multipart\/form-data&quot; action=&quot;.\/&quot; method=post&gt;\r\n&lt;table style=&quot;border:2px #000 solid&quot;&gt;\r\n  &lt;tr&gt;&lt;th&gt;\u753b\u50cf\u30d5\u30a1\u30a4\u30eb&lt;\/th&gt;&lt;td&gt;&lt;input type=&quot;file&quot; name=&quot;upfile&quot;&gt;&lt;\/td&gt;&lt;\/tr&gt;\r\n  &lt;tr&gt;&lt;th&gt;\u5909\u66f4\u5f8c\u306e\u753b\u50cf\u5e45 &#x5B;pixel]&lt;\/th&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;w&quot; value=&quot;100&quot;&gt;&lt;\/td&gt;&lt;\/tr&gt;\r\n&lt;\/table&gt;\r\n&lt;input name=&quot;exec&quot; type=&quot;submit&quot; value=&quot;JPEG,PNG,GIF\u753b\u50cf\u306e\u30b5\u30a4\u30ba\u3092\u5909\u66f4\u3057\u307e\u3059\u3002&quot;&gt;\r\n&lt;p style=&quot;border:2px #f00 solid;color:#f00;padding:2px;&quot;&gt;\r\n\u30fb\u5909\u63db\u53ef\u80fd\u306a\u753b\u50cf\u5f62\u5f0f\u306f JPEG, PNG, GIF\u306e3\u7a2e\u985e\u3068\u3059\u308b\u3002&lt;br \/&gt;\r\n\u30fb\u5165\u529b\u753b\u50cf\u306f\u4e00\u8fba\u304c20\uff5e1000\u30d4\u30af\u30bb\u30eb\u306e\u753b\u50cf\u3092\u51e6\u7406\u5bfe\u8c61\u3068\u3059\u308b\u3002&lt;br \/&gt;\r\n\u30fb\u51fa\u529b\u753b\u50cf\u30b5\u30a4\u30ba\u306f\u4e00\u8fba\u304c20\uff5e1000\u30d4\u30af\u30bb\u30eb\u306e\u7bc4\u56f2\u3067\u6307\u5b9a\u53ef\u80fd\u3068\u3059\u308b\u3002\r\n&lt;\/p&gt;\r\n&lt;\/form&gt;\r\n&lt;\/BODY&gt;\r\n&lt;\/HTML&gt;\r\n<\/pre>\n<h3 class=my_h3>img_resize.php<\/h3>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\nresize_img($_GET&#x5B;'fpath'], $_GET&#x5B;'w']);\r\n\r\n\/\/ \u753b\u50cf\u5909\u63db\uff06\u51fa\u529b\r\nfunction resize_img( $fpath, $w ){\r\n\r\n  \/\/ \u753b\u50cf\u60c5\u5831\u3092\u53d6\u5f97\r\n  $ary_info = getimagesize( $fpath );\r\n  if($ary_info === FALSE){\r\n    goto tagEND;\r\n  }\r\n  $img_w    = $ary_info&#x5B;0];\r\n  $img_h    = $ary_info&#x5B;1];\r\n  $img_type = $ary_info&#x5B;2];\r\n\r\n  \/\/ \u753b\u50cf\u30b5\u30a4\u30ba\u30c1\u30a7\u30c3\u30af\r\n  if(($img_w &gt; 1000) || ($img_h &gt; 1000)){\r\n    goto tagEND;\r\n  }\r\n  if(($img_w &lt; 20) || ($img_h &lt; 20)){\r\n    goto tagEND;\r\n  }\r\n\r\n  \/\/ \u753b\u50cf\u51e6\u7406\u3092\u9078\u629e\r\n  $func_create  = NULL;\r\n  $func_display = NULL;\r\n  switch( $img_type ){\r\n  case IMAGETYPE_JPEG:\r\n    $func_create  = &quot;imagecreatefromjpeg&quot;;\r\n    $func_display = &quot;imagejpeg&quot;;\r\n    break;\r\n  case IMAGETYPE_PNG:\r\n    $func_create  = &quot;imagecreatefrompng&quot;;\r\n    $func_display = &quot;imagepng&quot;;\r\n    break;\r\n  case IMAGETYPE_GIF:\r\n    $func_create  = &quot;imagecreatefromgif&quot;;\r\n    $func_display = &quot;imagegif&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\r\n  \/\/ \u753b\u50cf\u3092\u30ea\u30b5\u30a4\u30ba\r\n  $im_in  = $func_create( $fpath );\r\n  $dst_w = $w;\r\n  $dst_h = max(intval($img_h * $w \/ $img_w), 1);\r\n  $im_out = imagecreatetruecolor($dst_w, $dst_h);\r\n  imagecopyresampled($im_out, $im_in, 0, 0, 0, 0, $dst_w, $dst_h, $img_w, $img_h);\r\n\r\n  \/\/ HTTP\u5fdc\u7b54\u3068\u3057\u3066\u753b\u50cf\u3092\u51fa\u529b\r\n  $mime_type = image_type_to_mime_type( $img_type );\r\n  header(&quot;Content-Type: &quot;.$mime_type);\r\n  $func_display( $im_out );\r\n  imagedestroy( $im_in );\r\n  imagedestroy( $im_out );\r\ntagEND:\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=\"\/\/www.dogrow.net\/php\/sample\/00010\/\" target=\"_blank\">\/\/www.dogrow.net\/php\/sample\/00010\/<\/a><\/p>\n<hr class=my_hr_bottom>\n","protected":false},"excerpt":{"rendered":"<p>\u3084\u3063\u3066\u307f\u305f\u3044\u3053\u3068 \u4efb\u610f\u306eJPEG\u753b\u50cf\u30d5\u30a1\u30a4\u30eb\u3092WEB\u30d6\u30e9\u30a6\u30b6\u304b\u3089\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u3001\u6307\u5b9a\u30b5\u30a4\u30ba\u306b\u62e1\u5927\u30fb\u7e2e\u5c0f\u3057\u3066WEB\u30d6\u30e9\u30a6\u30b6\u306b\u8868\u793a\u3059\u308b\u3002 ImageMagick\u3067\u306f\u306a\u304f GD\u3092\u4f7f\u7528\u3059\u308b\u3002 \u3000\u2193 \u3000 \u5b9f\u884c\u30b5\u30f3\u30d7\u30eb\u306f\u3053\u3061\u3089\u3067\u3059\u3002\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/php\/blog10\/\">\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-130","post","type-post","status-publish","format-standard","hentry","category-gd","category-5","category-2"],"views":3511,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts\/130","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=130"}],"version-history":[{"count":15,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts\/130\/revisions"}],"predecessor-version":[{"id":791,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts\/130\/revisions\/791"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/media?parent=130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/categories?post=130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/tags?post=130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}