// 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)
function imgres($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);
$thumbnail=imagecreatetruecolor($x/$val,$y/$val);
$im_ridimensionata=imagecopyresized( $thumbnail, $im, 0, 0, 0, 0, $x/$val,
$y/$val, $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($x/$val,$y/$val);
$im_ridimensionata=imagecopyresized( $thumbnail, $im, 0, 0, 0, 0, $x/$val,
$y/$val, $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($x/$val,$y/$val);
$im_ridimensionata=imagecopyresized( $thumbnail, $im, 0, 0, 0, 0, $x/$val,
$y/$val, $x, $y);
imagepng($thumbnail, $salva, $q);
}
else{
echo "File not compatible(no jpg,gif or png)";
}
}
closedir($dh);
}
}
}