Annonceindlæg fra HP
17. april 2001 - 19:10
#7
<html> <head> <title>Untitled Document</title> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"> </head> <? define(\'IMAGE_DIR\',\'/cdrom/clipart/\'); // source dir define(\'IMAGE_STORE_DIR\',\'/opt/apache/htdocs/images/pic/\'); // destination dir define(\'IMAGE_TYPE\',\'jpg\'); // outout image type define(\'IMAGE_DEFAULT\',\'1\'); // force default size of: 1 = width , 0 = height define(\'IMAGE_DEFAULT_SMALL_H\',\'100\'); define(\'IMAGE_DEFAULT_SMALL_W\',\'100\'); define(\'IMAGE_DEFAULT_BIG_H\',\'600\'); define(\'IMAGE_DEFAULT_BIG_W\',\'480\'); define(\'IMAGE_STORE_PRIVILAGES\',\'0707\'); // live 0707 so the directories can\'t be browsed from grabbers define(\'IMAGE_JPEG_QUALITY\',\'50\'); define(\'DB_HOST\',\'192.168.11.100\'); define(\'DB_USER\',\'root\'); define(\'DB_PASS\',\'\'); define(\'DB_NAME\',\'cat_services\'); define(\'DB_TABLE_CAT\',\'photo_categories\'); define(\'DB_TABLE_DATA\',\'photo_data\'); $conn = mysql_connect(DB_HOST,DB_USER,DB_PASS); mysql_select_db(DB_NAME, $conn); function catID ($dir) { global $conn; $sid = explode(\'/\', substr($dir, strlen(IMAGE_DIR)-1) ); $query = mysql_query(\'select id from \' . DB_TABLE_CAT . \' where name=\"\' . $sid[sizeof($sid)-1]. \'\"\', $conn); if ( $result = mysql_fetch_row($query) ) { $id = $result[0]; } else { $cid = IMAGE_STORE_DIR; for ($i=0; $i<sizeof($sid); $i++) { mysql_query(\'insert into \' . DB_TABLE_CAT . \' (name,parent_id) values(\"\' . $sid[$i]. \'\",\"\' . $id . \'\") \',$conn); $id = mysql_insert_id(); @mkdir(IMAGE_STORE_DIR . $id, IMAGE_STORE_PRIVILAGES); } } return $id; } function grabDir($dir) { global $conn; $files = dir($dir); $files->read(); $files->read(); while ( $file = $files->read() ) { $current = \"$dir/$file\"; if ( is_dir($current) ) { grabDir($current); } elseif ( $img = getimagesize($current) ) { echo \"$current -> $img[0] x $img[1] x $img[2] \"; switch ($img[2]) { case 1: $sim = ImageCreateFromGIF($current); break; case 2: $sim = ImageCreateFromJPEG($current); break; case 3: $sim = ImageCreateFromPNG($current); break; default: break; } if ( IMAGE_DEFAULT ) { $dstW_small = IMAGE_DEFAULT_SMALL_W; $dstH_small = floor($dstW_small * $img[1] / $img[0]); $dstW_big = IMAGE_DEFAULT_BIG_W; $dstH_big = floor($dstW_big * $img[1] / $img[0]); } else { $dstH_small = IMAGE_DEFAULT_H; $dstW_small = floor($dstH_small * $img[0] / $img[1]); $dstH_big = IMAGE_DEFAULT_BIG_H; $dstW_big = floor($dstH_big * $img[0] / $img[1]); } $catID = catID($dir); mysql_query(\'insert into \' . DB_TABLE_DATA . \' set sW=\"\' . $dstW_small . \'\", sH=\"\' . $dstH_small . \'\", cat_id=\"\' . $catID . \'\", bW=\"\' . $dstW_big . \'\" , bH=\"\' . $dstH_big . \'\"\' ,$conn); $id = mysql_insert_id($conn); $dim_small = imagecreate($dstW_small, $dstH_small); $dim_big = imagecreate($dstW_big, $dstH_big); imagecopyresized($dim_small, $sim, 0, 0, 0, 0, $dstW_small, $dstH_small, $img[0], $img[1]); imagecopyresized($dim_big, $sim, 0, 0, 0, 0, $dstW_big, $dstH_big, $img[0], $img[1]); imagedestroy($sim); $destination = IMAGE_STORE_DIR . $catID . \'/\' . $id; switch (IMAGE_TYPE) { case \'gif\': ImageGIF($dim_small, $destination . \'s.\' . IMAGE_TYPE); ImageGIF($dim_big, $destination . \'b.\' . IMAGE_TYPE); break; case \'jpg\': ImageJPEG($dim_small, $destination . \'s.\' . IMAGE_TYPE, IMAGE_JPEG_QUALITY); ImageJPEG($dim_big, $destination . \'b.\' . IMAGE_TYPE, IMAGE_JPEG_QUALITY); break; case \'png\': ImagePNG($dim_small, $destination . \'s.\' . IMAGE_TYPE); ImagePNG($dim_big, $destination . \'b.\' . IMAGE_TYPE); break; case \'wbmp\': ImageWBMP($dim_small, $destination . \'s.\' . IMAGE_TYPE); ImageWBMP($dim_big, $destination . \'b.\' . IMAGE_TYPE); break; default: break; } imagedestroy($dim_big); imagedestroy($dim_small); mysql_query(\'update \' . DB_TABLE_DATA . \' set bsize=\"\' . filesize($destination . \'b.\' . IMAGE_TYPE) . \'\"\' ,$conn); echo \".. saved<br>\\n\"; flush(); } } $files->close(); unset($files); clearstatcache(); } echo \'Image converting...\'; grabDir(IMAGE_DIR); ?> <body bgcolor=\"#FFFFFF\" text=\"#000000\"> </body> </html>