$input = file_get_contents("php://stdin");
で受け取ったメールをmail_mimeDecodeで処理しているのですが、
iPhoneから送られた画像を保存すると、縦向きの画像が横向きで保存されます。
調べてみると、iPhoneの場合は縦向きでも横向きで保存されるらしく、
'orientation'という値をいじれば良いところまではわかったのですが、
上記のやり方の場合、向きを直すことは可能でしょうか。
<追記>
「上記のやり方の場合、向きを直すことは可能でしょうか。」
こちらですが、
file_get_contents、mail_mimeDecodeで画像を取得、保存した場合、
その画像情報から'orientation'の変更が可能か、という意味です。
誤解する表現でしたので、追記いたします。
<追記(メール情報から画像をファイル保存するまでの処理>
<?php $input = file_get_contents("php://stdin"); $structure = mail_mimeDecode($input); if (strtolower($structure->ctype_primary) == "multipart") { $images = getImage($structure->parts); } reset($images); // 拡張子を格納 $ext = ''; $count = 0; $count_max = count($images); foreach ($images as $image) { if ($image['type'] == 'image/jpeg' || $image['type'] == 'image/gif' || $image['type'] == 'image/png') { $count++; // ファイルとして保存($pathDir_tmpImageは一時ファイルを保存するディレクトリ名です) $tmp_path = tempnam($pathDir_tmpImage, 'img_'); if ($tmp_path == false) { break; } $fp = fopen($tmp_path, 'w'); if ($fp == false) { break; } fwrite($fp, $image['body']); fclose($fp); // ここから、一時ファイルを加工して別ディレクトリに保存します。(*) } function mail_mimeDecode($input){ list($headers,$body) = splitBodyHeader($input); return decode($headers, $body); } function splitBodyHeader($input){ if (preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $input, $match)) { return array($match[1], $match[2]); } return false; } function getImage($parts) { $images = array(); foreach( $parts as $part ){ print($part->ctype_primary. '/'.$part->disposition .'<br />'); // タイプ判別 if (isset($part->disposition) && (strtolower($part->disposition) == "attachment")) { $images[] = array( 'type' => strtolower(sprintf("%s/%s",$part->ctype_primary, $part->ctype_secondary)), 'name' => $part->ctype_paramaters['name'], 'body' => $part->body, ); } else { switch(strtolower($part->ctype_primary)){ case "image": $images[] = array( 'type' => strtolower(sprintf("%s/%s", $part->ctype_primary, $part->ctype_secondary)), 'name' => $part->crype_paramaters['name'], 'body' => $part->body, ); break; case "multipart": $images = array_merge($images, getImage($part->parts)); break; default: break; } } } return $images; } ?>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/28 13:33
退会済みユーザー
2018/05/28 13:34
2018/05/29 03:32
2018/05/29 04:06