- /**
- * Linux image server with thumbnails
- * Edit bbs.it-home.org
- */
- $ PicID = $ _ GET ['imgid'];
- $ PicTypes = ".". $ _ GET ['imgtype'];
- $ PicWidth = $ _ GET ['imgwidth'];
- If ($ picID! = "")
- {
- // The request is a thumbnail.
- If ($ picWidth> 0 ){
- // If the thumbnail exists
- If (file_exists ($ picID. "_". $ picWidth. $ picTypes ))
- {
- OutputImg ($ picID. "_". $ picWidth. $ picTypes );
- } Else
- {
- If (file_exists ($ picID. "_ 0". $ picTypes )){
- // Generate a thumbnail directly if no thumbnail exists
- ResizeImg ($ picID. "_ 0". $ picTypes, $ picWidth, $ picWidth, $ picID. "_". $ picWidth. $ picTypes );
- // Output
- OutputImg ($ picID. "_". $ picWidth. $ picTypes );
- } Else
- {
- // If the large image does not exist
- ResizeImg('noDefaultImage.gif ', $ picWidth, $ picWidth, noDefaultImage. "_". $ picWidth. ". gif ");
- // Output
- OutputImg ($ picID. "_". $ picWidth. $ picTypes );
- }
- }
- }
- // Determine whether a large image exists in the file
- If (file_exists ($ picID. "_ 0". $ picTypes ))
- {
- $ Img_file = $ picID. "_ 0". $ picTypes;
- OutputImg ($ img_file );
- }
- Else
- {
- // If no image exists
- $ Img_file = 'noDefaultImage.gif ';
- OutputImg ($ img_file );
- }
- }
- // Output image
- Function outputImg ($ img_file)
- {
- $ Fp = fopen ($ img_file, 'RB ');
- $ Content = fread ($ fp, filesize ($ img_file); // binary data
- Fclose ($ fp );
- Header ('content-Type: image/gif ');
- Echo $ content;
- }
- /**
- * Generating thumbnails
- * $ SrcName ---- Original Image path
- * $ NewWidth, $ newHeight ---- maximum width and height of the thumbnails respectively
- * $ NewName ---- name of the thumbnail file (including the path)
- * @ Param string $ srcName
- * @ Param int $ newWidth
- * @ Param int $ newHeight
- * @ Param string $ newName
- * Return viod
- */
- Function resizeImg ($ srcName, $ newWidth, $ newHeight, $ newName = "")
- {
- If ($ newName = "")
- {
- $ NameArr = explode ('.', $ srcName );
- $ ExpName = array_pop ($ nameArr );
- $ ExpName = $ expName;
- Array_push ($ nameArr, $ expName );
- $ NewName = implode ('.', $ nameArr );
- }
- $ Info = "";
- $ Data = getimagesize ($ srcName, $ info );
- Switch ($ data [2])
- {
- Case 1:
- If (! Function_exists ("imagecreatefromgif ")){
- Echo "your GD library cannot use images in GIF format. please use Jpeg or PNG format! Return ";
- Exit ();
- }
- $ Im = ImageCreateFromGIF ($ srcName );
- Break;
- Case 2:
- If (! Function_exists ("imagecreatefromjpeg ")){
- Echo "your GD library cannot use images in jpeg format. please use images in other formats! Return ";
- Exit ();
- }
- $ Im = ImageCreateFromJpeg ($ srcName );
- Break;
- Case 3:
- $ Im = ImageCreateFromPNG ($ srcName );
- Break;
- }
- $ SrcW = ImageSX ($ im );
- $ SrcH = ImageSY ($ im );
- $ NewWidthH = $ newWidth/$ newHeight;
- $ SrcWH = $ srcW/$ srcH;
- If ($ newWidthH <= $ srcWH ){
- $ FtoW = $ newWidth;
- $ FtoH = $ ftoW * ($ srcH/$ srcW );
- }
- Else {
- $ FtoH = $ newHeight;
- $ FtoW = $ ftoH * ($ srcW/$ srcH );
- }
- If ($ srcW> $ newWidth | $ srcH> $ newHeight)
- {
- If (function_exists ("imagecreatetruecolor "))
- {
- @ $ Ni = ImageCreateTrueColor ($ ftoW, $ ftoH );
- If ($ ni) ImageCopyResampled ($ ni, $ im, 0, 0, 0, $ ftoW, $ ftoH, $ srcW, $ srcH );
- Else
- {
- $ Ni = ImageCreate ($ ftoW, $ ftoH );
- ImageCopyResized ($ ni, $ im, 0, 0, 0, $ ftoW, $ ftoH, $ srcW, $ srcH );
- }
- }
- Else
- {
- $ Ni = ImageCreate ($ ftoW, $ ftoH );
- ImageCopyResized ($ ni, $ im, 0, 0, 0, $ ftoW, $ ftoH, $ srcW, $ srcH );
- }
- If (function_exists ('imagejpeg ') imagejpeg ($ ni, $ newName );
- Else ImagePNG ($ ni, $ newName );
- ImageDestroy ($ ni );
- }
- ImageDestroy ($ im );
- }
- ?>
|