images = $images; $this->thumbs = $thumbs; $this->thumb_prefix = $thumb_prefix; $this->image_types = $image_types; } function list_images($dir) { $all = array(); if(@opendir($dir)) { while (($file = @readdir($dir)) != false) { $type = strtolower(end(explode('.', $file))); if(($file != '.') && ($file != '..') && !is_dir($file) && in_array($type, $this->image_types)) $all[] = $file; } closedir($dir); } else exit('Directory can\'t be opened.'); return $all; } function thumb_checker() { $images_all = $this->list_images($this->images); $thumbs_all = $this->list_images($this->thumbs); foreach($thumbs_all as $thumb) { $thumb = str_replace($this->thumb_prefix, '', $thumb); $key = array_search($thumb, $images_all); if($key) unset($images_all[$key]); } return $images_all; } function create_thumb($filename, $type, $width, $height) { ob_start(); $create = $this->images.$filename; switch ($type) { case 'jpg': $image = imagecreatefromjpeg($create); break; case 'png': $image = imagecreatefrompng($create); break; case 'gif': $image = imagecreatefromgif($create); break; default: die('Cannot create thumbnail.'); } $thumb = imagecreatetruecolor($width, $height); list($image_width, $image_height) = getimagesize($this->images.$filename); imagecopyresampled($thumb, $image, 0, 0, 0, 0, $width, $height, $image_width, $image_height); imagedestroy($image); switch ($type) { case 'jpg': imagejpeg($thumb); break; case 'png': imagepng($thumb); break; case 'gif': imagegif($thumb); break; } $new_image = ob_get_contents(); $open = fopen($this->thumbs.$this->thumb_prefix.$filename, 'w'); fwrite($open, $new_image); fclose($open); ob_end_clean(); } function displayGallery($width, $height) { $thumbs_needed = $this->thumb_checker(); foreach($thumbs_needed as $new) { $type = strtolower(end(explode('.', $new))); $this->create_thumb($new, $type, $height, $width); } $all_images = $this->list_images($this->thumbs); foreach($all_images as $all) echo ''; } } $gallery = new ImageGallery(); $gallery->displayGallery(40, 40); ?>