Viewing file: reescalado_imagen.php (2.38 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
// a function for resize the images(png,jpg,gif) in a directory //for the png you must have the zlib actived
//$diror origin directory //$dirdest destination directory //$val value of resize(1,2,3..) //$qual quality(80 if you don't know) $origen='../frames/includes/'; $destino='../frames/includes2/'; $resize=1; $calidad=70;
imgress($origen,$destino,$resize,$calidad);
function imgress($diror,$dirdest,$val,$qual){ $q=$qual; //open the directory if (is_dir($diror)) { if ($dh = opendir($diror)) { while (($file = readdir($dh)) !== false) { if($file == "." || $file == ".."){continue;} $k=explode(".",$file); if(strpos($k[1],"jpg")===0 || strpos($k[1],"jpeg")===0){ $salva=$dirdest.$file; $image=$diror.$file; $im =imagecreatefromjpeg("$image"); $x=imagesx($im); $y=imagesy($im); if ($x<>132 or $y<>216){ $k=array("salidaenfalso","salidaenfalso"); } $thumbnail=imagecreatetruecolor(132,216); $im_ridimensionata=imagecopyresized( $thumbnail, $im, 0, 0, 0, 0, 132, 216, $x, $y); imagejpeg($thumbnail, $salva, $q); } elseif(strpos($k[1],"gif")===0){ $salva=$dirdest.$file; $image=$diror.$file; $im =imagecreatefromgif("$image"); $x=imagesx($im); $y=imagesy($im); $thumbnail=imagecreatetruecolor(132,216); $im_ridimensionata=imagecopyresized( $thumbnail, $im, 0, 0, 0, 0, 132, 216, $x, $y); imagegif($thumbnail, $salva, $q); } elseif(strpos($k[1],"png")===0){ $salva=$dirdest.$file; $image=$diror.$file; $im =imagecreatefrompng("$image"); $x=imagesx($im); $y=imagesy($im); $thumbnail=imagecreatetruecolor(132,216); $im_ridimensionata=imagecopyresized( $thumbnail, $im, 0, 0, 0, 0, 132, 216, $x, $y); imagepng($thumbnail, $salva, $q); } else{ echo "$diror File not compatible(no jpg,gif or png)"; } flush(); } closedir($dh); }else{ echo "no se pudo abrir"; } } }
?>
|