<?php

if(preg_match("/^[A-z]:.+/",__FILE__)){

$separator = '\\';
}else{
$separator = '/';
}
define("TEXTTOHTML_IMAGE_DIR_PATH", dirname(dirname(__FILE__)).$separator.'images'.$separator);


if(isset($_GET['i']) and !empty($_GET['i'])){

$file = file_get_contents("allow");

			$max_width = 1200;
			$thum_width = "";
			//重複を避けるために番号を追加
			if(isset($_GET['num']) and !empty($_GET['num'])){
			$indv_num = htmlspecialchars($_GET['num']);
			}else{
			$indv_num = "";
			}
			
			$file = htmlspecialchars($file);
		
			
			$save_file = TEXTTOHTML_IMAGE_DIR_PATH."$indv_num".basename($file);


          $uri = trim($file);
file_put_contents("allow","");		  

          list($width, $height, $type, $attr)=getimagesize($uri);
            if($width > $max_width){$width = $max_width;}

          if($thum_width == ""){$thum_width = $width;}
            $thum_height = $height*($thum_width / $width);
		
            $gdimg = imagecreatetruecolor($thum_width,$thum_height);

            if($type == 1)  {
              $im 		= imagecreatefromgif($uri);
            }
            if($type == 2)  {
              $im     	= imagecreatefromjpeg($uri);
            }
            if($type == 3)  {
              $im     	= imagecreatefrompng($uri);
            }
            if($type == 15) {
				$im     = imagecreatefromwbmp($uri);
            }

    imagecopyresized($gdimg,$im,0,0,0,0,$thum_width,$thum_height,$width,$height);
  /*
   *画像の種類を 示すフラグです。
   * 1 = GIF, 2 = JPG, 3 =PNG, 4 = SWF, 5 = PSD,
   * 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order),
   * 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM
   ---------------------------------------------------------------------*/
  
  if(!file_exists($save_file)){
           if($type == 1)  {
		   
		   
		    @imagegif($gdimg,$save_file);
			header('Content-type: image/gif');

              imagegif($gdimg);
            }
            elseif($type == 2){
			
			
			@imagejpeg($gdimg,$save_file);			
			header('Content-type: image/jpeg');
             imagejpeg($gdimg);
            }
            elseif($type == 3){
			@imagepng($gdimg,$save_file);			
			header('Content-type: image/png');

              imagepng($gdimg);

            }
			imagedestroy($gdimg);

}			

}else{

exit;

}
		
?>





