$size[1]) {//fat images $srcSizeX = $size[1]; $srcSizeY = $size[1]; $srcY = 0; $srcX = ($size[0]-$size[1])/2; } else if($size[0]<$size[1]) { //tall images $srcSizeX = $size[0]; $srcSizeY = $size[0]; $srcX = 0; $srcY = ($size[1]-$size[0])/2; } else { //square $srcY = 0; $srcX = 0; $srcSizeX = $size[0]; $srcSizeY = $size[0]; } $yoffset = 0; //draw in dest at 0,0 $xoffset = 0; $newWidth = $dim; $newHeight = $dim; } else { if($size[0]>$size[1]) { //fat images $ratio = $size[0]/$dim; $newWidth=$dim; $newHeight = round($size[1]/$ratio,0); } else if($size[0]<$size[1]) { //tall images $ratio = $size[1]/$dim; $newWidth= round($size[0]/$ratio,0); $newHeight = $dim; } else { //square $newWidth = $dim; $newHeight = $dim; } $srcSizeX = $size[0]; $srcSizeY = $size[1]; $srcY = 0; //draw from src at 0,0 $srcX = 0; $yoffset = ($dim-$newHeight)/2; //draw in dest at offset $xoffset = ($dim-$newWidth)/2; if($yoffset<0) $yoffset=0; if($xoffset<0) $xoffset=0; } //make the new image if($gd_Version>=2) $destImage = imagecreatetruecolor( $dim, $dim); else $destImage = ImageCreate( $dim, $dim); $color = ImageColorAllocate($destImage,$image_bkgd[0],$image_bkgd[1],$image_bkgd[2]); imagefill($destImage, 0, 0, $color); //paint it white first //copy the passed image into the new image at the proper scale if($gd_Version>=2) imagecopyresampled( $destImage, $im, $xoffset, $yoffset, $srcX, $srcY, $newWidth, $newHeight, $srcSizeX, $srcSizeY ); else ImageCopyResized( $destImage, $im, $xoffset, $yoffset, $srcX, $srcY, $newWidth+1, $newHeight+1, $srcSizeX, $srcSizeY ); ImageDestroy($im); //clean up the old image if(checkExifversion()==1 && $autorotate==1) { $details = @exif_read_data($path); if(!empty($details['Orientation'])) { switch($details['Orientation']) { case 1: $rotation = 0; break; case 3: $rotation = 180; break; case 8: $rotation = 90; break; case 6: $rotation = 270; break; default: $rotation = 0; break; } if ($rotation>0) $destImage = @imagerotate($destImage,$rotation,$color); } } return $destImage; //return the new image } function makeSquareSIPS($path, $save, $dim) { global $image_crop; if($image_crop==1) { //zoom in and crop square $size = @GetImageSize($path); if($size[0]>$size[1]) $size[0] = $size[1]; $command = "sips -s format jpeg --cropToHeightWidth ".$size[0]." ".$size[0]." ".escapeshellarg($path)." --out ".escapeshellarg($save); exec($command); $command = "sips --resampleHeightWidthMax ".$dim." ".escapeshellarg($save); exec($command); } else { //pad it $command = "sips -s format jpeg --resampleHeightWidthMax ".$dim." --padToHeightWidth ".$dim." ".$dim." ".escapeshellarg($path)." --out ".escapeshellarg($save); exec($command); } if(checkExifversion()==1) { $details = @exif_read_data($path); if(!empty($details['Orientation'])) { switch($details['Orientation']) { case 1: $rotation = 0; break; case 3: $rotation = 180; break; case 6: $rotation = 90; break; case 8: $rotation = 270; break; default: $rotation = 0; break; } if($rotation>0) { //rotate it $command = "sips --rotate ".$rotation." ".escapeshellarg($save); exec($command); } } } } function makeScaled($path, $dim) { //This function will resize the image keeping the same aspect ratio //the max width or height will be $dim global $image_bkgd; $gd_Version = checkGDversion(); if($gd_Version<1) return -1; if(stristr($path,".png")) $im = @imagecreatefrompng($path); else $im = @imagecreatefromjpeg($path); if(!$im) return -1; $size = @GetImageSize($path); if(checkExifversion()==1 && $autorotate==1) { $details = @exif_read_data($path); if(!empty($details['Orientation'])) { switch($details['Orientation']) { case 1: $rotation = 0; break; case 3: $rotation = 180; break; case 8: $rotation = 90; break; case 6: $rotation = 270; break; default: $rotation = 0; break; } if ($rotation>0) { $im = @imagerotate($im,$rotation,0); if($rotation==90 || $rotation==270) { $temp = $size[0]; $size[0]=$size[1]; $size[1]=$temp; } } } } if($size[0]<=$dim && $size[1]<=$dim) return $im; if($size[0]>$size[1]) { //fat images $ratio = $size[0]/$dim; $newWidth=$dim; $newHeight = round($size[1]/$ratio,0); } else if($size[0]<$size[1]) { //tall images $ratio = $size[1]/$dim; $newWidth= round($size[0]/$ratio,0); $newHeight = $dim; } else { //square $newWidth = $dim; $newHeight = $dim; } //make the new image if($gd_Version>=2) $destImage = imagecreatetruecolor( $newWidth, $newHeight); else $destImage = ImageCreate( $newWidth, $newHeight); $color = ImageColorAllocate($destImage,$image_bkgd[0],$image_bkgd[1],$image_bkgd[2]); imagefill($destImage, 0, 0, $color); //paint it white first //copy the passed image into the new image at the proper scale if($gd_Version>=2) imagecopyresampled( $destImage, $im, 0, 0, 0, 0, $newWidth, $newHeight, $size[0], $size[1] ); else ImageCopyResized( $destImage, $im, 0, 0, 0, 0, $newWidth+1, $newHeight+1, $size[0], $size[1] ); ImageDestroy($im); //clean up the old image return $destImage; //return the new image } function makeScaledSIPS($path, $save, $dim) { $command = "sips -s format jpeg --resampleHeightWidthMax ".$dim." ".escapeshellarg($path)." --out ".escapeshellarg($save); exec($command); if(checkExifversion()==1) { $details = @exif_read_data($path); if(!empty($details['Orientation'])) { switch($details['Orientation']) { case 1: $rotation = 0; break; case 3: $rotation = 180; break; case 6: $rotation = 90; break; case 8: $rotation = 270; break; default: $rotation = 0; break; } if($rotation>0) { //rotate it $command = "sips --rotate ".$rotation." ".escapeshellarg($save); exec($command); } } } } //Scans the directory and puts the photo names in an array function getPhotoList($path) { global $sort_method; $photos = array(); $srcTime=0; $extra = 1000; if(!is_dir($path)) return -1; if($d = dir($path)) { while (false !== ($entry = $d->read())) { $extra++; if(stristr($entry,".jpg") || stristr($entry,".png")) { if($sort_method>2) $srcTime = @filemtime($path."/".$entry).$extra; else $srcTime++; $photos[$srcTime] = $entry; } } $d->close(); } else { return -2; } if($sort_method==1) asort($photos); if($sort_method==2) arsort($photos); if($sort_method==3) ksort($photos); if($sort_method==4) krsort($photos); return $photos; } //Scans the directory and puts the sub-directory names in an array function getDirList($path) { global $sort_method; $dirs = array(); $srcTime=0; $extra = 1000; if(!is_dir($path)) return -1; if($d = dir($path)) { while (false !== ($entry = $d->read())) { $extra++; if(substr($entry,0,1)!="." && !eregi("_cache",$entry) && is_dir($path."/".$entry)) { if($sort_method>2) $srcTime = filemtime($path."/".$entry).$extra; else $srcTime++; $dirs[$srcTime] = $entry; } } $d->close(); } else { return -2; } if($sort_method==1) asort($dirs); if($sort_method==2) arsort($dirs); if($sort_method==3) ksort($dirs); if($sort_method==4) krsort($dirs); return $dirs; } function truncate($name, $len) { global $show_extension; if($show_extension==0) $name = substr($name,0, strrpos($name,".")); if(strlen($name)<=$len) return $name; return substr($name,0,$len-1)."..."; } function rmdirR($dir) { $handle = opendir($dir); while (false!==($e = readdir($handle))) { if($e != "." && $e != "..") { if(is_dir("$dir/$e")) rmdirR("$dir/$e"); else @unlink("$dir/$e"); } } closedir($handle); $worked = @rmdir($dir); return $worked; } function sanatizePath($path) { $path = str_replace("..","",$path); //remove .. to prevent viewing higher directories $path = strip_tags($path); //remove html tags to prevent XSS return $path; } //END FUNCTIONS //START OUTPUT GENERATION $version = "2.51"; //login if(!empty($HTTP_POST_VARS['admin'])) { if(!empty($password) && $HTTP_POST_VARS['admin']==$password) { setcookie ("admin", md5($HTTP_POST_VARS['admin']), time() + 7200); $_COOKIE['admin']=md5($HTTP_POST_VARS['admin']); } else { setcookie ("admin", '', time() - 7200); $_COOKIE['admin']=""; } if(!empty($HTTP_POST_VARS['path'])) $HTTP_GET_VARS['path'] = $HTTP_POST_VARS['path']; if(!empty($HTTP_POST_VARS['file'])) $HTTP_GET_VARS['file'] = $HTTP_POST_VARS['file']; if(!empty($HTTP_POST_VARS['op'])) $HTTP_GET_VARS['op'] = $HTTP_POST_VARS['op']; } //logout if(!empty($HTTP_GET_VARS['admin'])) { setcookie ("admin", '', time() - 7200); $_COOKIE['admin']=""; } if(!isset($HTTP_GET_VARS['op'])) $HTTP_GET_VARS['op']=0; if(!empty($HTTP_GET_VARS['path'])) $HTTP_GET_VARS['path'] = sanatizePath($HTTP_GET_VARS['path']); if(!empty($HTTP_GET_VARS['file'])) $HTTP_GET_VARS['file'] = sanatizePath($HTTP_GET_VARS['file']); if(!empty($HTTP_GET_VARS['rename'])) $HTTP_GET_VARS['rename'] = sanatizePath($HTTP_GET_VARS['rename']); if(empty($HTTP_GET_VARS['path'])) $file_path = "."; else $file_path = "./".$HTTP_GET_VARS['path']; if(empty($HTTP_GET_VARS['path'])) $web_path = ""; else $web_path = $HTTP_GET_VARS['path']; if(!empty($HTTP_GET_VARS['file'])) $HTTP_GET_VARS['file'] = $HTTP_GET_VARS['file']; if(empty($web_path)) $slash=""; else $slash = "/"; //delete file or folder if(!empty($admin) && $admin==1 && isset($HTTP_GET_VARS['del']) && $HTTP_GET_VARS['del']==1 && (!empty($HTTP_GET_VARS['path']) || !empty($HTTP_GET_VARS['file'])) && !empty($_COOKIE['admin']) && $_COOKIE['admin']==md5($password)) { if(empty($HTTP_GET_VARS['file'])) { rmdirR($file_path); rmdirR("./_cache/".$HTTP_GET_VARS['path']); if($display_errors==1 && file_exists($file_path)) { echo "
| ".$l_del_fol_err." |
| ".$l_del_fil_err." |
| ".$l_rename_err." |
Your gallery has been setup.
Everything looks good so far. Please check these default settings for your new gallery.