if it is not landscape format, calculate new height&width //to fit the new format ... if($ge_th == 1){ //if it is a thumbnail if($ge_ls == 2){ //not landscape $height = $ext_picWidth; $ext_picWidth = ceil($oldWidth*$height/$oldHeight); }else{ //if landscape, then only reset the height $height = ceil($oldHeight*$ext_picWidth/$oldWidth); } } else { // for large pics if($ge_ls == 2){ $height = $ext_picWidth; $ext_picWidth = ceil($oldWidth*$ext_picWidth/$oldHeight); }else{ //if landscape, then only reset the height $height = ceil($oldHeight*$ext_picWidth/$oldWidth); } } switch($info[2]){ //info[2] has img type info case 1: $oldImage = imagecreatefrompng($imagePath.$sourceImage); break; case 2; $oldImage = imagecreatefromjpeg($imagePath.$sourceImage); break; } //create the image object (true color, with different size parameters) $newImage = imagecreatetruecolor($ext_picWidth, $height); //resize the image imagecopyresized($newImage, $oldImage, 0, 0, 0, 0, $ext_picWidth, $height, $oldWidth, $oldHeight); //generate a local image if(($thumbExists == 0) && ($ge_th == 1)){ if(!file_exists("../thumbs/$album".".albfile")){ //generate file in the thumbs folder to note that the album exists touch("../thumbs/$album".".albfile"); //change mode of the *.albfile to 777 chmod("../thumbs/$album".".albfile", 0777); } //touch-solution from posts in: http://www.php.net/manual/en/function.imagejpeg.php touch($path2thumb); //create a local image from $newImage to the thumbs folder imagejpeg($newImage,$path2thumb, $thumbDefQuality); chmod($path2thumb, 0777); } if($out == 1){ //send header header("Content-Type: image/jpeg"); //output the picture if($_SESSION[grayscale]==1) greyscaleFast(&$newImage); if($_SESSION[grayscale]==2) greyscaleGood(&$newImage); imagejpeg($newImage,"",$se_quality); imagedestroy($newImage); imagedestroy($oldImage); } } function greyscaleGood (&$image) { $imagex = imagesx($image); $imagey = imagesy($image); for ($x = 0; $x <$imagex; ++$x) { for ($y = 0; $y <$imagey; ++$y) { $rgb = imagecolorat($image, $x, $y); $red = ($rgb >> 16) & 255; $green = ($rgb >> 8) & 255; $blue = $rgb & 255; $grey = (int)(($red+$green+$blue)/3); $newcol = imagecolorallocate($image, $grey,$grey,$grey); imagesetpixel($image, $x, $y, $newcol); } } } function greyscaleFast(&$img, $dither=1) { if (!($t = imagecolorstotal($img))) { $t = 256; imagetruecolortopalette($img, $dither, $t); } //$t = 256; //imagetruecolortopalette($img, $dither, $t); for ($c = 0; $c < $t; $c++) { $col = imagecolorsforindex($img, $c); $min = min($col['red'],$col['green'],$col['blue']); $max = max($col['red'],$col['green'],$col['blue']); $i = ($max+$min)/2; imagecolorset($img, $c, $i, $i, $i); } } ?>