示例#1
0
        /// <summary>
        /// if width and height can not be determined, returns a new size with isEmpty = true.
        /// </summary>
        /// <param name="config"></param>
        /// <param name="filename"></param>
        /// <param name="longestSidePixels"></param>
        /// <param name="shortestSidePixels"></param>
        /// <returns></returns>
        protected static System.Drawing.Size getDisplayWidthAndHeight(BaseShowThumbnailPageParameters config, string filename, int displayBoxWidth, int displayBoxHeight)
        {
            string FullSizeImageFilenameOnDisk = config.fullSizeImageStorageDir + filename;
            string cacheKey = getImageCacheKey(FullSizeImageFilenameOnDisk, displayBoxWidth, displayBoxHeight);

            ImageDiskCache diskCache = new ImageDiskCache(config.diskCacheStorageDirectoryPath);

            if (config.useDiskCache && diskCache.ExistsInCache(cacheKey, Path.GetExtension(FullSizeImageFilenameOnDisk)))
            {
                string fn = diskCache.CacheKeyToFilename(cacheKey, Path.GetExtension(FullSizeImageFilenameOnDisk));
                return(Thumbnail2.getDisplayWidthAndHeight(fn, displayBoxWidth, displayBoxHeight));
            }
            else if (File.Exists(FullSizeImageFilenameOnDisk))
            {
                return(Thumbnail2.getDisplayWidthAndHeight(FullSizeImageFilenameOnDisk, displayBoxWidth, displayBoxHeight));
            }
            else
            {
                return(new System.Drawing.Size());
            }
        }
示例#2
0
        protected void Process_Page_Load(BaseShowThumbnailPageParameters config)
        {
            string requestFile      = PageUtils.getFromForm("file", "");
            int    displayBoxWidth  = PageUtils.getFromForm("w", 0);
            int    displayBoxHeight = PageUtils.getFromForm("h", 0);

            // -- get the full sized image filename on disk
            string FullSizeImageFilenameOnDisk = "";
            // requestFile could have the Application path in it, and the config.fullSizeImageStorageDir could also making the file impossible to find
            // so let's remove it from requestFile
            string appPath = Request.ApplicationPath;

            if (!appPath.EndsWith("/"))
            {
                appPath += "/";
            }
            if (requestFile.StartsWith(appPath))
            {
                requestFile = requestFile.Substring(appPath.Length);
            }

            FullSizeImageFilenameOnDisk = config.fullSizeImageStorageDir + requestFile;

            if (FullSizeImageFilenameOnDisk == "" || !File.Exists(FullSizeImageFilenameOnDisk))
            {
                return;
            }

            string imgExtension = Path.GetExtension(FullSizeImageFilenameOnDisk);

            // -- check the cache for the image key
            string cacheKey = getImageCacheKey(FullSizeImageFilenameOnDisk, displayBoxWidth, displayBoxHeight);

            byte[] imageContent = null;
            if (config.useMemoryCache)
            {
                imageContent = CheckMemoryCache(cacheKey);
            }

            if (imageContent == null && config.useDiskCache && config.diskCacheStorageDirectoryPath != "" && Directory.Exists(config.diskCacheStorageDirectoryPath))
            {
                ImageDiskCache diskCache = new ImageDiskCache(config.diskCacheStorageDirectoryPath);
                imageContent = diskCache.getFromCache(cacheKey, imgExtension);
            }

            if (imageContent == null)
            {
                imageContent = Thumbnail2.CreateThumbnail(FullSizeImageFilenameOnDisk, displayBoxWidth, displayBoxHeight);
            }

            if (imageContent != null)
            {
                // -- save to cache
                if (config.useMemoryCache)
                {
                    InsertIntoMemoryCache(cacheKey, imageContent);
                }
                if (config.useDiskCache)
                {
                    ImageDiskCache diskCache = new ImageDiskCache(config.diskCacheStorageDirectoryPath);
                    diskCache.addToCache(cacheKey, imgExtension, imageContent);
                }

                // -- serve the image binary data
                serveImageContent(imgExtension, imageContent);
            }
        } // Process_Page_Load