<?php
	require("../__common__/__define_common.php");
	require("../__common__/include-common-all.php");
	require("../account/__logincheck.php");
	if ($_SESSION['システム管理者'] <> "YES") {
		exit;
	}
	if (photo_JPEG_ROTATE <> 'YES') {
		exit;
	}
	$file_name = my_GET('img');
	if ($file_name == '') {
		exit;
	}
	$rotate = $_GET['ro'];
	if ($rotate <> 'r' and $rotate <> 'l') {
		exit;
	}
/* azure_cui
	$rotate_file = $file_name.'.rot';
	$file_SJIS = myfile_ENCODE(str_replace('/', "\\", $file_name));
	$rotate_SJIS = myfile_ENCODE(str_replace('/', "\\", $rotate_file));
	exec('azure_cui -'.$rotate.' -e -c -w "'.$file_SJIS.'" "'.$rotate_SJIS.'"', $out, $ret);
	if (file_exists($rotate_SJIS)) {
		myfile_unlink($file_name);
		myfile_rename($rotate_file, $file_name);
		if (photo_JPEG_RESIZE == 'YES') {
			if (($resize_file = resize_new($file_name)) <> '') {
				$resize_SJIS = myfile_ENCODE($resize_file);
				if (!file_exists($resize_SJIS)) {
					$file_SJIS = $resize_SJIS;
				}
			}
		}
	}
*/
	$file_SJIS = myfile_ENCODE(str_replace('/', "\\", $file_name));
	if ($rotate == 'r') {
		$trans = '3';
	} else {
		$trans = '5';
	}
	exec('i_view32 "'.$file_SJIS.'" /jpg_rotate=('.$trans.',1,0,1,0,0,1,0) /convert=', $out, $ret);
	if (photo_JPEG_RESIZE == 'YES') {
		if (($resize_file = resize_new($file_name)) <> '') {
			$resize_SJIS = myfile_ENCODE($resize_file);
			if (!file_exists($resize_SJIS)) {
				$file_SJIS = $resize_SJIS;
			}
		}
	}
	if ($fp = fopen($file_SJIS, "rb")) {
		if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
			$file_name = myfile_ENCODE(substr($file_name,strrpos($file_name,'/')+1));
		} else {
			$file_name = urlencode(substr($file_name,strrpos($file_name,'/')+1));
		}
		header('Content-type: image/jpeg; name='.$file_name);
		header('Content-Disposition: inline; filename='.$file_name);
		fpassthru($fp);
	}
function resize_new($img_file) {		// UTF-8
	$attr = getimagesize(myfile_ENCODE($img_file));
	$width = $attr[0];
	$height = $attr[1];
	if ($width > $height) {
		$checksize = $width;
	} else {
		$checksize = $height;
	}
	$resize_file = '';
	if ($checksize > photo_RESIZE_SIZE_SMALL) {
		$resize_file = img_resize($img_file, photo_RESIZE_SIZE_SMALL, photo_RESIZE_DIR_SMALL);
	}
	if ($checksize > photo_RESIZE_SIZE_THUMB) {
		img_resize($img_file, photo_RESIZE_SIZE_THUMB, photo_RESIZE_DIR_THUMB);
	}
	return $resize_file;
}
function img_resize($img_file, $size, $dir) {		// UTF-8
	$resize_file = resize_filename($img_file, $dir);
	$resize_SJIS = myfile_ENCODE(str_replace('/', "\\", $resize_file));
	$img_SJIS = myfile_ENCODE(str_replace('/', "\\", $img_file));
	exec('i_view32 "'.$img_SJIS.'" /resize=('.$size.','.$size.') /aspectratio /convert="'.$resize_SJIS.'"');
	return $resize_file;
}
function resize_filename($img_file, $dir) {		// UTF-8
	$resize_dir = up_folder_path($img_file).$dir;
	return ($resize_dir.basename($img_file));
}
?>
