3 function getPreview($imgFile, $maxSize = THUMB_SIZE)
5 # example: data/myalbum/100.mypic.jpg
6 $newImgFile = DATA_DIR."/".dirname($imgFile)."/".$maxSize.".".basename($imgFile);
8 # if the preview is a symlink, image is already good sized
9 if (is_link($newImgFile)) return $imgFile;
11 if (! is_file($newImgFile))
13 # this tels the template to flush output after displaying previews
14 $GLOBALS["generating"] = true;
16 # reset script time limit to 20s (wont work in safe mode)
19 $ext = strtolower(substr($imgFile, -4));
21 $img = imagecreatefromjpeg($imgFile);
23 $img = imagecreatefrompng($imgFile);
27 # if the image is already small and squared, make a symlink and return it
28 if ($w <= $maxSize and $h <= $maxSize and $w == $h) {
30 symlink($imgFile, $newImgFile);
34 # config to allow group writable files
36 # create the thumbs directory recursively
37 if (! is_dir(dirname($newImgFile))) mkdir(dirname($newImgFile), 0777, true);
42 $srcX = ($w - $srcSize)/2;
46 $srcY = ($h - $srcSize)/2;
52 $newImg = imagecreatetruecolor(THUMB_SIZE, THUMB_SIZE);
54 imagecopyresampled($newImg, $img, 0, 0, $srcX, $srcY, THUMB_SIZE, THUMB_SIZE, $srcSize, $srcSize);
57 imagejpeg($newImg, $newImgFile);
59 imagepng($newImg, $newImgFile);
62 imagedestroy($newImg);