defPath = "./image/"; } public function UpLoad() { if (is_uploaded_file($this->tmpUpLoadFile)) { if (move_uploaded_file($this->tmpUpLoadFile, $this->defPath . $this->fileName)) { chmod($this->defPath . $this->fileName, 0666); } return true; } else { return false; } } /** * 画像の幅の調整とリネームを行う * return 実行結果(0:成功 -1:失敗) */ public function ResizeImage($path, $length) { $result = 0; //実行結果 //縦,横の幅を取得 list($iwidth, $iheight) = getimagesize($this->defPath . $this->fileName); //縦横比を計算し縦横の長さを決定 $proportion = $iwidth / $iheight; if ($proportion < 1) { $height = $length; $width = $length * $proportion; } else { $height = $length / $proportion; $width = $length; } //新しい画像の生成 if (($this->ext == "jpg") || ($this->ext == "jpeg") || ($this->ext == "JPG")) { $src = imagecreatefromjpeg($this->defPath . $this->fileName); } else { $src = imagecreatefrompng($this->defPath . $this->fileName); } //画像領域の作成 $image = imagecreatetruecolor($width, $height); //サムネイル画像の生成 imagecopyresampled($image, $src, 0, 0, 0, 0, $width, $height, $iwidth, $iheight); if (($this->ext == "jpg") || ($this->ext == "jpeg") || ($this->ext == "JPG")) { if (!imagejpeg($image, $path . $this->fileName)) { $result = -1; } } else { if (!imagepng($image, $path . $this->fileName)) { $result = -1; } } imagedestroy($image); unset($image, $src, $proportion, $iwidth, $iheight, $image, $src, $width, $height); if ($result >= 0) { return true; } else { return false; } } public function checkExt() { $this->ext = pathinfo($this->defPath . $this->upLoadFile, PATHINFO_EXTENSION); //拡張子チェック } public function imageRotation() { // 調べたい画像のパス $exif_data = exif_read_data($this->defPath . $this->fileName); //新しい画像の生成 if (($this->ext == "jpg") || ($this->ext == "jpeg") || ($this->ext == "JPG")) { $src = imagecreatefromjpeg($this->defPath . $this->fileName); } else { $src = imagecreatefrompng($this->defPath . $this->fileName); } if (isset($exif_data['Orientation'])) { //画像の回転処理 $orientation = $exif_data['Orientation']; // 未定義 if ($orientation == 0) {//未定義 } else if ($orientation == 1) {//通常 } else if ($orientation == 2) { } else if ($orientation == 3) {// 端末上下反転 $src = imagerotate($src, 180, 0); } else if ($orientation == 4) { } else if ($orientation == 5) { } else if ($orientation == 6) {// 時計回りに90°回転 $src = imagerotate($src, 270, 0); } else if ($orientation == 7) { } else if ($orientation == 8) {// 反時計回りに90°回転 $src = imagerotate($src, 90, 0); } if (($this->ext == "jpg") || ($this->ext == "jpeg") || ($this->ext == "JPG")) { imagejpeg($src, $this->defPath . $this->fileName); } else { imagepng($src, $this->defPath . $this->fileName); } } } /* -------------▼セッター▼------------- */ public function setFileName($fileName) { $this->fileName = $fileName; } public function setExt($ext) { $this->ext = $ext; } public function setUpLoadFile($upLoadFile) { $this->upLoadFile = $upLoadFile; } public function getTmpUpLoadFile() { return $this->tmpUpLoadFile; } /* -------------▲セッター▲------------- */ /* -------------▼ゲッター▼------------- */ public function getFileName() { return $this->fileName; } public function getExt() { return $this->ext; } public function getUpLoadFile() { return $this->upLoadFile; } public function setTmpUpLoadFile($tmpUpLoadFile) { $this->tmpUpLoadFile = $tmpUpLoadFile; } /* -------------▲ゲッター▲------------- */ }