//Copyright (c)2006 David L Rudie //This uses the BSD License // Create thumbnail if CRC and filesize are ok. if($_GET['nothumbnails'] != 1) { if(!file_exists('./'.$scanner.$arr['path'].'thumbnails/'.$arr['name']) && $crcok == 1 && $filesizeok == 1 && ($arr['havefile'] != 0 || $hddhavefile != 0)) { $old_image = './'.$scanner.$arr['path'].$arr['name']; $new_image = './'.$scanner.$arr['path'].'thumbnails/'.$arr['name']; if(preg_match("/.(gif)/i", $arr['name'])) { $src_image = imagecreatefromgif($old_image); } elseif(preg_match("/.(jpg)/i", $arr['name'])) { $quality = 100; $src_image = imagecreatefromjpeg($old_image); } $src_width = imagesx($src_image); $src_height = imagesy($src_image); $dest_width = 150; $dest_height = 100; $dst_width = $dest_width; $dst_height = $dest_height; $ar = $dest_width / $dest_height; $divX = $src_width / $dest_width; if($src_height / $divX <= $dest_height) { $y = 0; $dest_height = $src_height / $divX; $cropheight = $src_height; $dy = ($dst_height / 2) - (($src_height / $divX) / 2); } else { $cropheight = $src_width / $ar; $y = $src_height / $divX; $y = ($y - $dest_height) * $divX / 2; $dy = 0; } if(preg_match("/.(gif)/i", $arr['name'])) { $dst_image = imagecreate($dst_width, $dst_height); imagecopyresized($dst_image, $src_image, 0, $dy, 0, $y, $dest_width, $dest_height, $src_width, $cropheight); imagegif($dst_image, $new_image); } elseif(preg_match("/.(jpg)/i", $arr['name'])) { $dst_image = imagecreatetruecolor($dst_width, $dst_height); imagecopyresampled($dst_image, $src_image, 0, $dy, 0, $y, $dest_width, $dest_height, $src_width, $cropheight); imagejpeg($dst_image, $new_image, $quality); } imagedestroy($src_image); imagedestroy($dst_image); } }