home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 January / PCWorld_2003-01_cd.bin / Software / Topware / zme / zme5-trcz.exe / board1.ZHT / main.js < prev    next >
Encoding:
Text File  |  2002-11-21  |  5.6 KB  |  164 lines

  1. function GeneratePreview(cSourcePath, cDestPath, cID)
  2. {
  3.   //MessageBox("cSourcePath = " + cSourcePath + "\ncDestPath = " + cDestPath + "\ncID = " + cID, "Preview", MB_OK);
  4. }
  5.  
  6. function GetPageFN(iPage) {
  7.   if (iPage == 1) {
  8.     return "index.htm";
  9.   }
  10.  
  11.   return "page" + IntToStr(iPage, 5) + ".htm";
  12. }
  13.  
  14. var iThnWidth = 160;
  15. var iThnHeight = 120;
  16. var rcThn;
  17.  
  18. function ProcessImage(pImg, pDestImg) {
  19.   pImg.Resize(rcThn.Width()-4, rcThn.Height()-4, GFX_KEEP_ASPECT | GFX_INTERPOLATE);
  20.   var rcResized = pImg.GetRect();
  21.  
  22.   pImg.Shadow(iShadowColor, iShadowAlpha*2.55, iShadowXOffset, iShadowYOffset, iShadowBlur, 0);
  23.  
  24.   //pImg.Resize(rcThn.Width(), rcThn.Height(), GFX_KEEP_ASPECT | GFX_INTERPOLATE);
  25.   var rcResized = pImg.GetRect();
  26.  
  27.   var fAngle = Math.random()*fMaxAngle*2-fMaxAngle;
  28.   pImg.Rotate(fAngle, 0, GFX_INTERPOLATE);
  29.  
  30.   var rcImg = pImg.GetRect();
  31.  
  32.   var iOffsetX = (iThnWidth - rcImg.Width()) / 2;
  33.   var iOffsetY = (iThnHeight - rcImg.Height()) / 2;
  34.  
  35.   pImg.Draw(pDestImg, rcImg, iOffsetX, iOffsetY, 255, GFX_KEEP_ALPHA);
  36.  
  37.   return GetRotatedImageMap(rcResized, fAngle, iOffsetX, iOffsetY);
  38. }
  39.  
  40. function GenerateAlbum(cSourcePath, cDestPath)
  41. {
  42.   rcThn = CalcRectBeforeRotate(fMaxAngle, iThnWidth, iThnHeight);
  43.  
  44.   var iFilesCount = lSelectedFiles.GetCount();
  45.  
  46.   var iPagesCount = Math.ceil(iFilesCount / 9);
  47.  
  48.   CopyFile(cSourcePath + "0101.jpg", cDestPath + "0101.jpg", FIL_OM_OVERWRITE);
  49.  
  50.   CopyFile(cSourcePath + "0201.jpg", cDestPath + "0201.jpg", FIL_OM_OVERWRITE);
  51.   CopyFile(cSourcePath + "0203.jpg", cDestPath + "0203.jpg", FIL_OM_OVERWRITE);
  52.   CopyFile(cSourcePath + "0205.jpg", cDestPath + "0205.jpg", FIL_OM_OVERWRITE);
  53.   CopyFile(cSourcePath + "0207.jpg", cDestPath + "0207.jpg", FIL_OM_OVERWRITE);
  54.  
  55.   CopyFile(cSourcePath + "0301.jpg", cDestPath + "0301.jpg", FIL_OM_OVERWRITE);
  56.  
  57.   CopyFile(cSourcePath + "0401.jpg", cDestPath + "0401.jpg", FIL_OM_OVERWRITE);
  58.   CopyFile(cSourcePath + "0403.jpg", cDestPath + "0403.jpg", FIL_OM_OVERWRITE);
  59.   CopyFile(cSourcePath + "0405.jpg", cDestPath + "0405.jpg", FIL_OM_OVERWRITE);
  60.   CopyFile(cSourcePath + "0407.jpg", cDestPath + "0407.jpg", FIL_OM_OVERWRITE);
  61.  
  62.   CopyFile(cSourcePath + "0501.jpg", cDestPath + "0501.jpg", FIL_OM_OVERWRITE);
  63.  
  64.   CopyFile(cSourcePath + "0601.jpg", cDestPath + "0601.jpg", FIL_OM_OVERWRITE);
  65.   CopyFile(cSourcePath + "0603.jpg", cDestPath + "0603.jpg", FIL_OM_OVERWRITE);
  66.   CopyFile(cSourcePath + "0605.jpg", cDestPath + "0605.jpg", FIL_OM_OVERWRITE);
  67.   CopyFile(cSourcePath + "0607.jpg", cDestPath + "0607.jpg", FIL_OM_OVERWRITE);
  68.  
  69.   CopyFile(cSourcePath + "0701.jpg", cDestPath + "0701.jpg", FIL_OM_OVERWRITE);
  70.  
  71.   var tPage = new CTemplate();
  72.   tPage.Load(cSourcePath + "page.tpl", 0);
  73.  
  74.   tPage.SetReplace("${TITLE}", cTitle);
  75.   tPage.SetReplace("${HEAD_FONT_SIZE}", iHeaderFontSize);
  76.   tPage.SetReplace("${HEAD_FONT_COLOR}", HEXColor(iHeaderFontColor));
  77.   tPage.SetReplace("${FOOT_FONT_SIZE}", iFooterFontSize);
  78.   tPage.SetReplace("${FOOT_FONT_COLOR}", HEXColor(iFooterFontColor));
  79.   tPage.SetReplace("${HEADER}", ReplaceExifStrings(cHeader, "", ""));
  80.   tPage.SetReplace("${FOOTER}", ReplaceExifStrings(cFooter, "", ""));
  81.  
  82.   var tImg = new CTemplate();
  83.   tImg.Load(cSourcePath + "img.tpl", 0);
  84.  
  85.   var tNoImg = new CTemplate();
  86.   tNoImg.Load(cSourcePath + "noimg.tpl", 0);
  87.  
  88.   var tMap = new CTemplate();
  89.   tMap.Load(cSourcePath + "map.tpl", 0);
  90.  
  91.   var iPage = 1;
  92.   var iImg = 1;
  93.   var cMaps = "";
  94.  
  95.   for (var iFile = 1; ((iFile <= iFilesCount) || (iImg != 1)); iFile++) {
  96.     if (iFile <= iFilesCount) {
  97.  
  98.       var cFileName = lSelectedFiles.GetAt(iFile-1);
  99.       var cImgFileName = "img" + IntToStr(iFile, 5) + ".jpg";
  100.       var cThnFileName = "thn" + IntToStr(iPage, 3) + "-" + iImg + ".jpg";
  101.       var cMapName = "imgMap" + iImg;
  102.  
  103.       var pOrigImg = new CImage();
  104.       pOrigImg.Load(cFileName, 0);
  105.  
  106.       pOrigImg.Resize(iImgWidth, iImgHeight, GFX_KEEP_ASPECT | GFX_INTERPOLATE);
  107.       pOrigImg.SaveAs(cDestPath + cImgFileName, JPGformat, iImgJPEG, 0);
  108.  
  109.       var pImg = new CImage();
  110.       pImg.Load(cSourcePath + "img" + iImg + ".jpg", 0);
  111.       var cMapCoords = ProcessImage(pOrigImg, pImg);
  112.       pImg.SaveAs(cDestPath + cThnFileName, JPGformat, iTNJPEG, 0);
  113.  
  114.       tMap.SetReplace("${MAP_NAME}", cMapName);
  115.       tMap.SetReplace("${MAP_HREF}", cImgFileName);
  116.       tMap.SetReplace("${MAP_COORDS}", cMapCoords);
  117.       cMaps += tMap.Replace();
  118.  
  119.       tImg.SetReplace("${THN_FILENAME}", cThnFileName);
  120.       tImg.SetReplace("${THN_MAPNAME}", cMapName);
  121.  
  122.       tPage.SetReplace("${IMG"+iImg+"}", tImg.Replace()); 
  123.  
  124.       pImg.Close();
  125.       pOrigImg.Close();
  126.  
  127.     } else { // no other files to process, make table complete
  128.       var cThnFileName = "thn" + IntToStr(iPage, 3) + "-" + iImg + ".jpg";
  129.       CopyFile(cSourcePath + "img" + iImg + ".jpg", cDestPath + cThnFileName, FIL_OM_OVERWRITE);
  130.       tNoImg.SetReplace("${THN_FILENAME}", cThnFileName);
  131.  
  132.       tPage.SetReplace("${IMG"+iImg+"}", tNoImg.Replace()); 
  133.     }
  134.  
  135.     iImg++;
  136.  
  137.     if (iImg > 9) {
  138.       if (iPage > 1) {
  139.         tPage.SetReplace("${PREV}", "  <a href=\""+GetPageFN(iPage-1)+"\"><<</a>");
  140.       } else {
  141.         tPage.SetReplace("${PREV}", "  ");
  142.       }
  143.       if (iPage < iPagesCount) {
  144.         tPage.SetReplace("${NEXT}", "<a href=\""+GetPageFN(iPage+1)+"\">>></a>  ");
  145.       } else {
  146.         tPage.SetReplace("${NEXT}", "  ");
  147.       }
  148.       tPage.SetReplace("${MAPS}", cMaps);
  149.       SaveString(cDestPath + GetPageFN(iPage), tPage.Replace(), 0);
  150.  
  151.       cMaps = "";
  152.       iImg = 1;
  153.  
  154.       iPage++;
  155.     }
  156.  
  157.   }
  158.  
  159.   return cDestPath + GetPageFN(1);
  160.   
  161. }
  162.  
  163. INIT_OK;
  164.