{"id":60,"date":"2015-07-19T18:24:22","date_gmt":"2015-07-19T09:24:22","guid":{"rendered":"http:\/\/medicalfields.jp\/blog\/?p=60"},"modified":"2017-03-02T14:04:04","modified_gmt":"2017-03-02T05:04:04","slug":"php%e3%81%a7androidiphone%e3%81%8b%e3%82%89%e3%81%ae%e7%94%bb%e5%83%8f%e3%81%ae%e5%9b%9e%e8%bb%a2%e5%87%a6%e7%90%86","status":"publish","type":"post","link":"https:\/\/medicalfields.jp\/blog\/%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%9f%e3%83%b3%e3%82%b0\/php%e3%81%a7androidiphone%e3%81%8b%e3%82%89%e3%81%ae%e7%94%bb%e5%83%8f%e3%81%ae%e5%9b%9e%e8%bb%a2%e5%87%a6%e7%90%86\/","title":{"rendered":"PHP\u3067android,iphone\u304b\u3089\u306e\u753b\u50cf\u306e\u56de\u8ee2\u51e6\u7406"},"content":{"rendered":"<p>Android\u3084iPhone\u3067\u306f\u753b\u50cf\u3092\u4fdd\u5b58\u3057\u305f\u6642\u7e26\u6a2a\u306e\u30b5\u30a4\u30ba\u3067\u306f\u306a\u304fExif\u306eOrientation\u3067\u753b\u50cf\u306e\u5411\u304d\u3092\u7ba1\u7406\u3057\u3066\u3044\u308b\u3089\u3057\u3044\u3002<\/p>\n<p>\u306a\u308b\u307b\u3069\u3001\u305d\u306e\u307e\u307e\u7e2e\u5c0f\u3057\u3066\u3082\u5411\u304d\u304c\u304a\u304b\u3057\u3044\u306f\u305a\u3060\u3002<\/p>\n<p>\u3088\u3063\u3066Orientation\u3092\u8003\u616e\u3057\u305f\u52d5\u4f5c\u304c\u5fc5\u8981\u306b\u306a\u308b\u3002<\/p>\n<pre>\/\/ \u30b3\u30d4\u30fc\u5143\u753b\u50cf\u306e\u6307\u5b9a\r\n$targetImage = $target_path;\r\n\/\/ \u30d5\u30a1\u30a4\u30eb\u540d\u304b\u3089\u3001\u753b\u50cf\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\r\n$image = imagecreatefromjpeg($targetImage);\r\n\/\/ \u30b3\u30d4\u30fc\u5143\u753b\u50cf\u306e\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u3092\u53d6\u5f97\r\nlist($image_w, $image_h) = getimagesize($targetImage);\r\n\r\n\/\/ \u51fa\u529b\u3059\u308b\u753b\u50cf\u30b5\u30a4\u30ba\u306e\u6307\u5b9a\r\n\/\/$width =640;\r\n\/\/$height = $width*$image_h\/$image_w;\r\n\r\n\r\n$min_width = 800; \/\/ \u5e45\u306e\u6700\u4f4e\u30b5\u30a4\u30ba\r\n$min_height = 800; \/\/ \u9ad8\u3055\u306e\u6700\u4f4e\u30b5\u30a4\u30ba\r\n\r\n\r\nif($image_w == $image_h) {\r\n   $width = $min_width;\r\n   $height = $min_height;\r\n} else if($image_w &gt; $image_h) {\/\/\u6a2a\u9577\u306e\u5834\u5408\r\n   $width = $min_width;\r\n   $height = $image_h*($min_width\/$image_w);\r\n} else if($image_w &lt; $image_h) {\/\/\u7e26\u9577\u306e\u5834\u5408\r\n   $width = $image_w*($min_height\/$image_h);\r\n   $height = $min_height;\r\n}\r\n\r\n\r\n\/\/ \u30b5\u30a4\u30ba\u3092\u6307\u5b9a\u3057\u3066\u3001\u80cc\u666f\u7528\u753b\u50cf\u3092\u751f\u6210\r\n$canvas = imagecreatetruecolor($width, $height);\r\n\r\n\/\/ \u80cc\u666f\u753b\u50cf\u306b\u3001\u753b\u50cf\u3092\u30b3\u30d4\u30fc\u3059\u308b\r\nimagecopyresampled($canvas,  \/\/ \u80cc\u666f\u753b\u50cf\r\n      $image,   \/\/ \u30b3\u30d4\u30fc\u5143\u753b\u50cf\r\n      0,        \/\/ \u80cc\u666f\u753b\u50cf\u306e x \u5ea7\u6a19\r\n      0,        \/\/ \u80cc\u666f\u753b\u50cf\u306e y \u5ea7\u6a19\r\n      0,        \/\/ \u30b3\u30d4\u30fc\u5143\u306e x \u5ea7\u6a19\r\n      0,        \/\/ \u30b3\u30d4\u30fc\u5143\u306e y \u5ea7\u6a19\r\n      $width,   \/\/ \u80cc\u666f\u753b\u50cf\u306e\u5e45\r\n      $height,  \/\/ \u80cc\u666f\u753b\u50cf\u306e\u9ad8\u3055\r\n      $image_w, \/\/ \u30b3\u30d4\u30fc\u5143\u753b\u50cf\u30d5\u30a1\u30a4\u30eb\u306e\u5e45\r\n      $image_h  \/\/ \u30b3\u30d4\u30fc\u5143\u753b\u50cf\u30d5\u30a1\u30a4\u30eb\u306e\u9ad8\u3055\r\n);\r\n\r\n\r\n\r\n$exif_datas = exif_read_data($target_path);\r\n\/\/\u8fd4\u308a\u5024\u3068\u3057\u3066\u9023\u60f3\u914d\u5217\u3067Exif\u60c5\u5831\u304c\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002\r\n\r\n\/\/var_dump($exif_datas);\r\nif(isset($exif_datas[\"Orientation\"])){\r\n if($exif_datas[\"Orientation\"]==6){\r\n\r\n \/\/ \u56de\u8ee2\r\n $canvas = imagerotate($canvas, 270, 0);\r\n\r\n }\r\n if($exif_datas[\"Orientation\"]==8){\r\n\r\n \/\/ \u56de\u8ee2\r\n $canvas = imagerotate($canvas, 90, 0);\r\n\r\n }\r\n if($exif_datas[\"Orientation\"]==3){\r\n\r\n \/\/ \u56de\u8ee2\r\n $canvas = imagerotate($canvas, 180, 0);\r\n\r\n }\r\n }\r\n\/\/ \u753b\u50cf\u3092\u51fa\u529b\u3059\u308b\r\nimagejpeg($canvas,           \/\/ \u80cc\u666f\u753b\u50cf\r\n      \".\/shohou_image_m\/\".$new_dir.\"\/\" . basename( $_FILES['f1']['name']).\"_0.jpg\",    \/\/ \u51fa\u529b\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u540d\uff08\u7701\u7565\u3059\u308b\u3068\u753b\u9762\u306b\u8868\u793a\u3059\u308b\uff09\r\n      100                \/\/ \u753b\u50cf\u7cbe\u5ea6\uff08\u3053\u306e\u4f8b\u3060\u3068100%\u3067\u4f5c\u6210\uff09\r\n);\r\n\r\n\/\/ \u30e1\u30e2\u30ea\u3092\u958b\u653e\u3059\u308b\r\nimagedestroy($canvas);<\/pre>\n<p>\u3053\u3093\u306a\u3068\u3053\u308d\u304b\u306a\u30fc<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Android\u3084iPhone\u3067\u306f\u753b\u50cf\u3092\u4fdd\u5b58\u3057\u305f\u6642\u7e26\u6a2a\u306e\u30b5\u30a4\u30ba\u3067\u306f\u306a\u304fExif\u306eOrientation\u3067\u753b\u50cf\u306e\u5411\u304d\u3092\u7ba1\u7406\u3057\u3066\u3044\u308b\u3089\u3057\u3044\u3002 \u306a\u308b\u307b\u3069\u3001\u305d\u306e\u307e\u307e\u7e2e\u5c0f\u3057\u3066\u3082\u5411\u304d\u304c\u304a\u304b\u3057\u3044\u306f\u305a\u3060\u3002 \u3088\u3063\u3066Orientation\u3092\u8003 &hellip; <a href=\"https:\/\/medicalfields.jp\/blog\/%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%9f%e3%83%b3%e3%82%b0\/php%e3%81%a7androidiphone%e3%81%8b%e3%82%89%e3%81%ae%e7%94%bb%e5%83%8f%e3%81%ae%e5%9b%9e%e8%bb%a2%e5%87%a6%e7%90%86\/\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">PHP\u3067android,iphone\u304b\u3089\u306e\u753b\u50cf\u306e\u56de\u8ee2\u51e6\u7406<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[8,7],"tags":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6kJO0-Y","_links":{"self":[{"href":"https:\/\/medicalfields.jp\/blog\/wp-json\/wp\/v2\/posts\/60"}],"collection":[{"href":"https:\/\/medicalfields.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/medicalfields.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/medicalfields.jp\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/medicalfields.jp\/blog\/wp-json\/wp\/v2\/comments?post=60"}],"version-history":[{"count":2,"href":"https:\/\/medicalfields.jp\/blog\/wp-json\/wp\/v2\/posts\/60\/revisions"}],"predecessor-version":[{"id":62,"href":"https:\/\/medicalfields.jp\/blog\/wp-json\/wp\/v2\/posts\/60\/revisions\/62"}],"wp:attachment":[{"href":"https:\/\/medicalfields.jp\/blog\/wp-json\/wp\/v2\/media?parent=60"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/medicalfields.jp\/blog\/wp-json\/wp\/v2\/categories?post=60"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/medicalfields.jp\/blog\/wp-json\/wp\/v2\/tags?post=60"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}