Compañias
SEGUROS EVER (Siempre Seguros)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ini_set("memory_limit","80M"); ############################################## # Shiege Iseng Resize Class # 11 March 2003 # shiegege_at_yahoo.com # View Demo : # http://shiege.com/scripts/thumbnail/ /*############################################ Sample : $thumb=new thumbnail("./shiegege.jpg"); // generate image_file, set filename to resize $thumb->size_width(100); // set width for thumbnail, or $thumb->size_height(300); // set height for thumbnail, or $thumb->size_auto(200); // set the biggest width or height for thumbnail $thumb->jpeg_quality(75); // [OPTIONAL] set quality for jpeg only (0 - 100) (worst - best), default = 75 $thumb->show(); // show your thumbnail $thumb->save("./huhu.jpg"); // save your thumbnail to file ---------------------------------------------- Note : - GD must Enabled - Autodetect file extension (.jpg/jpeg, .png, .gif, .wbmp) but some server can't generate .gif / .wbmp file types - If your GD not support 'ImageCreateTrueColor' function, change one line from 'ImageCreateTrueColor' to 'ImageCreate' (the position in 'show' and 'save' function) */############################################ class thumbnail { var $img; function redimensionar_imagen($imagen, $nombre_imagen_asociada) { //indicamos el directorio donde se van a colgar las imágenes $directorio = 'imagenes/' ; //establecemos los límites de ancho y alto $nuevo_ancho = 350 ; $nuevo_alto = 350 ; //Recojo información de la imágen $info_imagen = getimagesize($imagen); $alto = $info_imagen[1]; $ancho = $info_imagen[0]; $tipo_imagen = $info_imagen[2]; //Determino las nuevas medidas en función de los límites if($ancho > $nuevo_ancho OR $alto > $nuevo_alto) { if(($alto - $nuevo_alto) > ($ancho - $nuevo_ancho)) { $nuevo_ancho = round($ancho * $nuevo_alto / $alto,0) ; } else { $nuevo_alto = round($alto * $nuevo_ancho / $ancho,0); } } else //si la imagen es más pequeña que los límites la dejo igual. { $nuevo_alto = $alto; $nuevo_ancho = $ancho; } // dependiendo del tipo de imagen tengo que usar diferentes funciones switch ($tipo_imagen) { case 1: //si es gif ... $imagen_nueva = imagecreate($nuevo_ancho, $nuevo_alto); $imagen_vieja = imagecreatefromgif($imagen); //cambio de tamaño... imagecopyresampled($imagen_nueva, $imagen_vieja, 0, 0, 0, 0, $nuevo_ancho, $nuevo_alto, $ancho, $alto); if (!imagegif($imagen_nueva, $directorio . $nombre_imagen_asociada)) return false; break; case 2: //si es jpeg ... $imagen_nueva = imagecreatetruecolor($nuevo_ancho, $nuevo_alto); $imagen_vieja = imagecreatefromjpeg($imagen); //cambio de tamaño... imagecopyresampled($imagen_nueva, $imagen_vieja, 0, 0, 0, 0, $nuevo_ancho, $nuevo_alto, $ancho, $alto); if (!imagejpeg($imagen_nueva, $directorio . $nombre_imagen_asociada)) return false; break; case 3: //si es png ... $imagen_nueva = imagecreatetruecolor($nuevo_ancho, $nuevo_alto); $imagen_vieja = imagecreatefrompng($imagen); //cambio de tamaño... imagecopyresampled($imagen_nueva, $imagen_vieja, 0, 0, 0, 0, $nuevo_ancho, $nuevo_alto, $ancho, $alto); if (!imagepng($imagen_nueva, $directorio . $nombre_imagen_asociada)) return false; break; unlink($nombre_imagen_asociada); } return true; //si todo ha ido bien devuelve true } function thumbnail($imgfile) { //detect image format $this->img["format"]=ereg_replace(".*\.(.*)$","\\1",$imgfile); $this->img["format"]=strtoupper($this->img["format"]); if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") { //JPEG $this->img["format"]="JPEG"; $this->img["src"] = ImageCreateFromJPEG ($imgfile); } elseif ($this->img["format"]=="PNG") { //PNG $this->img["format"]="PNG"; $this->img["src"] = ImageCreateFromPNG ($imgfile); } elseif ($this->img["format"]=="GIF") { //GIF $this->img["format"]="GIF"; $this->img["src"] = ImageCreateFromGIF ($imgfile); } elseif ($this->img["format"]=="WBMP") { //WBMP $this->img["format"]="WBMP"; $this->img["src"] = ImageCreateFromWBMP ($imgfile); } else { //DEFAULT echo "Not Supported File"; exit(); } @$this->img["lebar"] = imagesx($this->img["src"]); @$this->img["tinggi"] = imagesy($this->img["src"]); //default quality jpeg $this->img["quality"]=75; } function size_height($size=100) { //height $this->img["tinggi_thumb"]=$size; @$this->img["lebar_thumb"] = ($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"]; } function size_width($size=100) { //width $this->img["lebar_thumb"]=$size; @$this->img["tinggi_thumb"] = ($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"]; } function size_auto($size=100) { //size if ($this->img["lebar"]>=$this->img["tinggi"]) { $this->img["lebar_thumb"]=$size; @$this->img["tinggi_thumb"] = ($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"]; } else { $this->img["tinggi_thumb"]=$size; @$this->img["lebar_thumb"] = ($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"]; } } function jpeg_quality($quality=75) { //jpeg quality $this->img["quality"]=$quality; } function show() { //show thumb @Header("Content-Type: image/".$this->img["format"]); /* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/ $this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]); @imagecopyresized ($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]); if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") { //JPEG imageJPEG($this->img["des"],"",$this->img["quality"]); } elseif ($this->img["format"]=="PNG") { //PNG imagePNG($this->img["des"]); } elseif ($this->img["format"]=="GIF") { //GIF imageGIF($this->img["des"]); } elseif ($this->img["format"]=="WBMP") { //WBMP imageWBMP($this->img["des"]); } } function save($save="") { //save thumb if (empty($save)) $save=strtolower("./thumb.".$this->img["format"]); /* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/ $this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]); @imagecopyresized ($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]); if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") { //JPEG imageJPEG($this->img["des"],"$save",$this->img["quality"]); } elseif ($this->img["format"]=="PNG") { //PNG imagePNG($this->img["des"],"$save"); } elseif ($this->img["format"]=="GIF") { //GIF imageGIF($this->img["des"],"$save"); } elseif ($this->img["format"]=="WBMP") { //WBMP imageWBMP($this->img["des"],"$save"); } } } ?>