ini_set('display_errors', '1');
#error_reporting(E_ALL);
$p=array();
$filename = "../index.txt";
if (file_exists($filename)){
$handle = fopen($filename, "r");
$f = fread($handle, filesize($filename));
fclose($handle);
$ln=split("\n",$f);
foreach($ln as $l){
// echo "[$l]";
list($k, $v)=split(':',$l,2);
$p[$k]=$v;
}
}
?>
#if (!file_exists('../tmp')) mkdir('../tmp',0777);
if ($handle = opendir('..')) {
$P=array();
while (false !== ($file = readdir($handle))) {
if (preg_match('/jpg/', $file) ||preg_match('/JPG/', $file) ){
#echo "$file ";
if (! file_exists("../tmp/$file")) {
create_jpgthumb("../$file", "../tmp/$file", 100, 100, 90, true);
}
$s=$p[$file];
$P[]=$file;
#echo "-
$s ";
}
}
closedir($handle);
}
sort($P);
foreach ($P as $a){
$s=$p[$file];
echo "-
$s ";
}
?>
function create_jpgthumb($original, $thumbnail, $max_width, $max_height, $quality, $scale = true) {
list ($src_width, $src_height, $type, $w) = getimagesize($original);
if ($type == 3) // cheking image type
$srcImage = imagecreatefrompng($original);
elseif ($type == 2)
$srcImage = imagecreatefromjpeg($original);
elseif ($type == 1)
$srcImage = imagecreatefromgif($original);
if (!$srcImage) {
return false;
}
# image resizes to natural height and width
if ($scale == true) {
if (($src_width/$max_width) > ($src_height/$max_height) ) {
$thumb_width = $max_width;
$thumb_height = floor($src_height * ($max_width / $src_width));
} else if (($src_width/$max_width) < ($src_height/$max_height) ) {
$thumb_height = $max_height;
$thumb_width = floor($src_width * ($max_height / $src_height));
} else {
$thumb_width = $max_height;
$thumb_height = $max_height;
}
if (!$destImage = imagecreatetruecolor($thumb_width, $thumb_height)) {
print ' imagecreatetruecolor(';
return false;
}
if (!imagecopyresampled($destImage, $srcImage, 0, 0, 0, 0, $thumb_width, $thumb_height, $src_width, $src_height)) {
print ' imagecopyresampled';
return false;
}
# image is fixed to supplied width and height and cropped
} else if ($scale == false) {
$ratio = $max_width / $max_height;
# thumbnail is landscape
if ($ratio > 1) {
# uploaded pic is landscape
if ($src_width > $src_height) {
$thumb_width = $max_width;
$thumb_height = ceil($max_width * ($src_height / $src_width));
if ($thumb_height > $max_width) {
$thumb_height = $max_width;
$thumb_width = ceil($max_width * ($src_width / $src_height));
}
# uploaded pic is portrait
} else {
$thumb_height = $max_width;
$thumb_width = ceil($max_width * ($src_height / $src_width));
if ($thumb_width > $max_width) {
$thumb_width = $max_width;
$thumb_height = ceil($max_width * ($src_height / $src_width));
}
$off_h = ($src_height - $src_width) / 2;
}
if (!$destImage = imagecreatetruecolor($max_width, $max_height)) {
return false;
}
if (!imagecopyresampled($destImage, $srcImage, 0, 0, 0, $off_h, $thumb_width, $thumb_height, $src_width, $src_height)) {
return false;
}
# thumbnail is square
} else {
if ($src_width > $src_height) {
$off_w = ($src_width - $src_height) / 2;
$off_h = 0;
$src_width = $src_height;
} else if ($src_height > $src_width) {
$off_w = 0;
$off_h = ($src_height - $src_width) / 2;
$src_height = $src_width;
} else {
$off_w = 0;
$off_h = 0;
}
if (!$destImage = imagecreatetruecolor($max_width, $max_height)) {
return false;
}
if (!imagecopyresampled($destImage, $srcImage, 0, 0, $off_w, $off_h, $max_width, $max_height, $src_width, $src_height)) {
return false;
}
}
}
imagedestroy($srcImage);
if (!imageantialias($destImage, true)) {
return false;
}
if ($type == 3) // cheking image type
$r=imagepng($destImage, $thumbnail, $quality); //png
elseif ($type == 2)
$r=imagejpeg($destImage, $thumbnail, $quality); //jpg
elseif ($type == 1)
$r=imagegif($destImage, $thumbnail, $quality); //gif
imagedestroy($destImage);
return true;
}
?>