<?php
/*
	Copyright(c) 2010 Shift Tech Inc. All Rights Reserved.
 	http://www.shift-tech.jp/

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

session_start();
$param = isset($_GET['param']) ? $_GET['param'] : '';
$data = '';
$ext = '';
if ($param != '') {
	$data  = isset($_SESSION["tmpImage"][$param]['data']) ? $_SESSION["tmpImage"][$param]['data'] : '';
	$ext  = isset($_SESSION["tmpImage"][$param]['ext']) ? $_SESSION["tmpImage"][$param]['ext'] : '';
} else {
	$data  = isset($_SESSION["tmpImage"]['data']) ? $_SESSION["tmpImage"]['data'] : '';
	$ext  = isset($_SESSION["tmpImage"]['ext']) ? $_SESSION["tmpImage"]['ext'] : '';
}

if($ext != '' && $data != '') {
	switch($ext) {
		case ".jpg": //jpgの場合
			header('Content-Type: image/jpeg');
			print($data);
			break;
		case ".gif":
			header("Content-type: image/gif");
			print($data);
			break;
		case ".png":
			header("Content-type: image/png");
			print($data); //要GD2.01以上
			break;
		case ".bmp":
			header("Content-type: image/vnd.wap.wbmp");
			print($data); //要GD2.01以上
			break;
		default:
		break;
	}
} else {
	//画像が無い場合はspacer表示
	header("Content-type: image/gif");
	$new_image = ImageCreateTrueColor(1,1);
	$bgcolor = ImageColorAllocate($new_image, 255, 255, 255);
	imagefill($new_image, 0, 0, $bgcolor);
	ImageGIF($new_image);
	imagedestroy($new_image);
}
?>