# Arquivo: thumb.php # Autor: Helbert Fernandes - estaleiroweb # baseado no trabalho de Mauricio Wolff if ($_SERVER['DOCUMENT_ROOT']) $base_file = $_SERVER['DOCUMENT_ROOT']; require getcwd()."/fileinc.php"; // Inclusão de funcões de Caminho e Diretório // Constantes: variaveis que não mudam em todo o programa define('MAX_WIDTH' , (isset($_GET['x']))?$_GET['x']:600); define('MAX_HEIGHT', (isset($_GET['y']))?$_GET['y']:1000); # Pega onde está a imagem if (strpos($_GET['img'],"http://")===false){ $temp=explode('/',$_GET['img']); $image_file = array_pop($temp); $image_path = implode('/',$temp); $image_path=caminhoAtivo().$image_path.(($image_path=='')?'':'/'); }else{ $img = $_GET["img"]."&docid=".$_GET["docid"]."&protocolo=".$_GET["protocolo"]; $image_file = $img; } # Carrega a imagem //if (!file_exists($image_path.$image_file)) $image_file=''; //$dataArquivo = filectime($image_path.$image_file); header("Last-Modified: " . gmdate("D, d M Y H:i:s",$dataArquivo) . " GMT"); switch (strtolower(end(explode('.',$image_file)))) { case 'jpg': header('Content-type: image/jpeg'); $strImg = getString($image_path.$image_file); $img = imagecreatefromstring($strImg); //$img = @imagecreatefromjpeg($image_path.$image_file); mostraImg('imagejpeg',$img,MAX_WIDTH,MAX_HEIGHT); break; case 'png': $img = @imagecreatefrompng($image_path.$image_file); mostraImg('imagepng',$img,MAX_WIDTH,MAX_HEIGHT); break; case 'gif': $img = @imagecreatefromgif($image_path.$image_file); mostraImg('imagegif',$img,MAX_WIDTH,MAX_HEIGHT); break; case 'bmp': $img = @imagecreatefromwbmp ($image_path.$image_file); mostraImg('imagewbmp',$img,MAX_WIDTH,MAX_HEIGHT); break; default: if (strpos($_GET['img'],"http://")!==false){ header( "Content-Type: image/jpeg"); LoadJPEG ($img); //imagejpeg($img, '', 100); }else{ $img = imagecreate(160, 120); imagecolorallocate($img, 204, 204, 204); $c = imagecolorallocate($img, 153, 153, 153); $c1 = imagecolorallocate($img, 0, 0, 0); imageline($img, 0, 0, 160, 120, $c); imageline($img, 160, 0, 0, 120, $c); imagestring($img, 5, 60, 20, "ERRO:", $c1); imagestring($img, 5, 65, 50, "Sem", $c1); imagestring($img, 5, 50, 70, "Imagem", $c1); mostraImg('imagejpeg',$img,MAX_WIDTH,MAX_HEIGHT); } } function tamanhoImg($img,$x,$y){ // Pega o tamanho da imagem e proporção de resize $width = imagesx($img); $height = imagesy($img); $scale = min($x/$width, $y/$height); // Se a imagem é maior que o permitido, encolhe ela! if ($scale < 1) { $new_width = floor($scale * $width); $new_height = floor($scale * $height); // Cria uma imagem temporária $tmp_img = imagecreatetruecolor($new_width, $new_height); // Copia e resize a imagem velha na nova imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); imagedestroy($img); $img = $tmp_img; } return $img; } function mostraImg($funcao,$img,$x,$y){ if (!function_exists($funcao)) $funcao='imagejpeg'; switch ($funcao) { case 'imagejpeg': //header('Content-type: image/jpeg'); if (strpos($_GET['img'],"http://")===false){ imagejpeg(tamanhoImg($img,$x,$y)); }else{ $img = abreRemoto($img); imagecreatefromjpeg($img); } break; case 'imagegif': //header('Content-type: image/gif'); imagegif(tamanhoImg($img,$x,$y)); break; case 'imagepng': //header('Content-type: image/png'); imagepng(tamanhoImg($img,$x,$y)); break; case 'imagewbmp': //header('Content-type: image/vnd.wap.wbmp'); imagewbmp(tamanhoImg($img,$x,$y)); break; } } function abreRemoto($arquivoRemoto){ $file = fopen ($arquivoRemoto, "r"); if (!$file) { echo "
Incapaz de abrir arquivo remoto.\n"; exit; } return $file; } function LoadJPEG ($imgURL) { ##-- Get Image file from Port 80 --## $fp = fopen($imgURL, "rb"); $fp; $imageFile = ""; do { $data = fread($fp, 8192); if (strlen($data) == 0) { break; } $imageFile = $data; imagejpeg ($imageFile); echo $imageFile; } while(true); fclose($fp); ##-- Create a temporary file on disk --## ##-- Load Image from Disk with GD library --## } function getString ($imgURL) { ##-- Get Image file from Port 80 --## $fp = fopen($imgURL, "rb"); $fp; $imageFile = ""; do { $data = fread($fp, 8192); if (strlen($data) == 0) { break; } $imageFile .= $data; } while(true); fclose($fp); return $imageFile; ##-- Create a temporary file on disk --## ##-- Load Image from Disk with GD library --## } ?>