Added support for png files

This commit is contained in:
Marc MAURICE 2010-10-08 00:11:01 +02:00
parent 4a35600a74
commit f20a06743f

View file

@ -9,7 +9,11 @@ function getPreview($imgFile, $maxSize = THUMB_SIZE)
if (! is_file($newImgFile)) if (! is_file($newImgFile))
{ {
$img = imagecreatefromjpeg($imgFile); $ext = strtolower(substr($file, -4));
if ($ext == ".jpg")
$img = imagecreatefromjpeg($imgFile);
else
$img = imagecreatefrompng($imgFile);
$w = imagesx($img); $w = imagesx($img);
$h = imagesy($img); $h = imagesy($img);
@ -34,7 +38,10 @@ function getPreview($imgFile, $maxSize = THUMB_SIZE)
imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h); imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h);
imagejpeg($newImg, $newImgFile); if ($ext == ".jpg")
imagejpeg($newImg, $newImgFile);
else
imagepng($newImg, $newImgFile);
imagedestroy($img); imagedestroy($img);
imagedestroy($newImg); imagedestroy($newImg);
@ -46,7 +53,8 @@ function getPreview($imgFile, $maxSize = THUMB_SIZE)
function getAlbumPreview($dir) function getAlbumPreview($dir)
{ {
foreach (scandir($dir) as $file) if ($file != '.' and $file != '..') { foreach (scandir($dir) as $file) if ($file != '.' and $file != '..') {
if (strtolower(substr($file, -4)) == ".jpg") $ext = strtolower(substr($file, -4));
if ($ext == ".jpg" or $ext == ".png")
return getPreview("$dir/$file"); return getPreview("$dir/$file");
} }
@ -84,7 +92,7 @@ foreach (scandir($realDir) as $file) if ($file != '.' and $file != '..')
else else
{ {
$ext = strtolower(substr($file, -4)); $ext = strtolower(substr($file, -4));
if ($ext == ".jpg") if ($ext == ".jpg" or $ext == ".png")
$imageFiles[] = array( "name" => $file, "url" => getPreview("$realDir/$file"), "link" => dirname($scriptUrlPath)."/view/$shortPath/$file" ); $imageFiles[] = array( "name" => $file, "url" => getPreview("$realDir/$file"), "link" => dirname($scriptUrlPath)."/view/$shortPath/$file" );
else else
$otherFiles[] = array( "name" => $file, "link" => dirname($scriptUrlPath)."/$realDir/$file" ); $otherFiles[] = array( "name" => $file, "link" => dirname($scriptUrlPath)."/$realDir/$file" );