<% '********************************************************************************* ' Picture Gallery Pro Fedor Skvortsov, COMobjectsNET. July, 2001 ' Mailto: support@COMobjectsNET ' WWW: http://COMobjectsNET '********************************************************************************* Dim intSize, strPath, strPhysicalPath, objFileSystem, objPictureProcessor, objIconGrabber 'Max size of the thumbnail intSize = CInt(Request.QueryString("size")) 'Relative path to the picture strPath = Request.QueryString("path") strPhysicalPath = Server.MapPath(Request.QueryString("path")) 'Prevent somebody from browsing the structure of the file system upper than Gallery root folder. If InStr(1, strPhysicalPath, Server.MapPath(strRootPath), 1) <> 1 Then Err.Raise 5054, "COMobjectsNET PictureGallery Script", "Security Error" End If Dim intNewWidth, intNewHeight, intWidth, intHeight Function SaveIcon Set objPictureProcessor = Nothing Set objIconGrabber = Server.CreateObject("COMobjectsNET.IconGrabber") objIconGrabber.FileName = strPhysicalPath Response.Clear objIconGrabber.SaveToFile objThumbnailFolder.Path & "\" & objFile.Name Set objIconGrabber = Nothing Response.Redirect strPath Response.End End Function Set objFileSystem = Server.CreateObject("Scripting.FileSystemObject") Dim objFile, objParentFolder, objThumbnailFolder Set objFile = objFileSystem.GetFile(strPhysicalPath) Set objParentFolder = objFile.ParentFolder 'If the \Thumbnails folder doesn't exist, create it. If objFileSystem.FolderExists(objParentFolder.Path & "\Thumbnails")=False Then Set objThumbnailFolder = objFileSystem.CreateFolder(objParentFolder.Path & "\Thumbnails") Else Set objThumbnailFolder = objFileSystem.GetFolder(objParentFolder.Path & "\Thumbnails") End If strPath = Left(strPath, Len(strPath) - Len(objFile.Name)) & "Thumbnails/" & objFile.Name 'If the thumbnail in the \Thumbnails folder doesn't exist, create it If objFileSystem.FileExists(objThumbnailFolder.Path & "\" & objFile.Name)=False Then Set objPictureProcessor = Server.CreateObject("COMobjects.NET.PictureProcessor") On Error Resume Next objPictureProcessor.LoadFromFile objParentFolder.Path & "\" & objFile.Name If Err.number<>0 Then SaveIcon End If ' Tuning JPEG options for the thumbnail objPictureProcessor.SmoothFactor = 50 objPictureProcessor.OptimizationOn = True objPictureProcessor.Quality = 75 intWidth=objPictureProcessor.Width intHeight=objPictureProcessor.Height intNewWidth = intSize intNewHeight = intHeight*intNewWidth/intWidth If intNewHeight>intNewWidth Then intNewHeight=intNewWidth intNewWidth = intWidth*intNewHeight/intHeight End If objPictureProcessor.Resize intNewWidth, intNewHeight objPictureProcessor.SaveToFileAsJpeg objThumbnailFolder.Path & "\" & objFile.Name If Err.number<>0 Then SaveIcon End If On Error Goto 0 Set objPictureProcessor = Nothing End If 'Redirect to the thumbnail Response.Redirect strPath 'Response.Redirect Replace(strPath, " ", "%20") %>