これを投稿したことを忘れていました。オリエンテーションの問題を処理する方法を見つけたので、共有したいと思いました。今はシンプルに見えます。それ以来、Codeigniter を使用してこのプロジェクトを再作成しました。CI は優れており、時間を大幅に節約できますが、初めて自分ですべてを書いてよかったと思っています。私は確かにそのようにもっと学びました。
まず、ファイルが jpg の場合、PELで EXIF データを取得します。
$new向きをチェックするアップロードされたファイルです。
$this->load->library('pel/PelJpeg');
if($ext == 'jpg'){
$pdw= new PelDataWindow(file_get_contents($new));
if(PelJpeg::isValid($pdw)){
$input_jpg = new PelJpeg($new);
$exif = $input_jpg->getExif();
}
}
次に、EXIF が存在する場合は、向きの値を取得して switch ステートメントを実行し、それに応じて回転させてから、向きの値をリセットします。私は image_moo と Codeigniter を使用していますが、これは明らかに任意の画像操作ライブラリを使用するように変更できます。
これらすべての IF ステートメントがそこにある必要があるかどうかは正直わかりませんが、EXIF 情報のみを含む jpg で問題が発生し続け、それらがないとスクリプトが壊れてしまいます。
if($exif !== NULL){
if($tiff = $exif->getTiff()){
if($ifd0 = $tiff->getIfd()){
if($orient = $ifd0->getEntry(PelTag::ORIENTATION)){
$this->image_moo->load($new);
//find the orientation value from the orientation tag. May be a better way, but this works for me.
$orientation = str_replace(' ', '', $orient);
//The orientation value from the orientation tag is after 'Value:'
if (($tmp = strstr($orientation, 'Value:')) !== false) {
$str = substr($tmp, 6, 1);
}
switch ($str)
{
// up is pointing to the right
case 8:
$this->image_moo->rotate(90);
$orient->setValue(1);
break;
// image is upside-down
case 3:
$this->image_moo->rotate(180);
$orient->setValue(1);
break;
// up is pointing to the left
case 6:
$this->image_moo->rotate(270);
$orient->setValue(1);
break;
// correct orientation
case 1:
break;
}
$this->image_moo->save($new,TRUE);
if ($this->image_moo->errors) print $this->image_moo->display_errors();
$this->image_moo->clear();
}
}
}
}
これが同じ問題に苦しんでいる他の誰かに役立つことを願っています. 改善できる点があれば、お知らせください。しかし、これは私にとってはうまくいきます。
マーク