Bloom.ImageProcessing.RuntimeImageProcessor.GetPathToResizedImage C# (CSharp) 메소드

GetPathToResizedImage() 공개 메소드

public GetPathToResizedImage ( string originalPath, bool getThumbnail = false ) : string
originalPath string
getThumbnail bool
리턴 string
        public string GetPathToResizedImage(string originalPath, bool getThumbnail = false)
        {
            //don't mess with Bloom UI images
            if (new[] {"/img/", "placeHolder", "Button"}.Any(s => originalPath.Contains(s)))
                return originalPath;

            var cacheFileName = originalPath;

            if (getThumbnail)
            {
                cacheFileName = "thumbnail_" + cacheFileName;
            }

            // check if this image is in the do-not-process list
            bool test;
            if (_imageFilesToReturnUnprocessed.TryGetValue(cacheFileName, out test)) return originalPath;

            lock (this)
            {
                // if there is a cached version, return it
                string pathToProcessedVersion;
                if (_originalPathToProcessedVersionPath.TryGetValue(cacheFileName, out pathToProcessedVersion))
                {
                    if (RobustFile.Exists(pathToProcessedVersion) &&
                        new FileInfo(originalPath).LastWriteTimeUtc <= new FileInfo(pathToProcessedVersion).LastWriteTimeUtc)
                    {
                        return pathToProcessedVersion;
                    }

                    // the file has changed, remove from cache
                    string valueRemoved;
                    _originalPathToProcessedVersionPath.TryRemove(cacheFileName, out valueRemoved);
                }

                // there is not a cached version, try to make one
                var pathToProcessedImage = Path.Combine(_cacheFolder, Path.GetRandomFileName() + Path.GetExtension(originalPath));

                if (!Directory.Exists(Path.GetDirectoryName(pathToProcessedImage)))
                    Directory.CreateDirectory(Path.GetDirectoryName(pathToProcessedImage));

                // BL-1112: images not loading in page thumbnails
                bool success;
                if (getThumbnail)
                {
                    // The HTML div that contains the thumbnails is 80 pixels wide, so make the thumbnails 80 pixels wide
                    success = GenerateThumbnail(originalPath, pathToProcessedImage, 80);
                }
                else
                {
                    success = MakePngBackgroundTransparent(originalPath, pathToProcessedImage);
                }

                if (!success)
                {
                    // add this image to the do-not-process list so we don't waste time doing this again
                    _imageFilesToReturnUnprocessed.TryAdd(cacheFileName, true);
                    return originalPath;
                }

                _originalPathToProcessedVersionPath.TryAdd(cacheFileName, pathToProcessedImage); //remember it so we can reuse if they show it again, and later delete

                return pathToProcessedImage;
            }
        }

Usage Example

 public void GetTinyImage_DoesNotChangeSize()
 {
     using (var cache = new RuntimeImageProcessor(new BookRenamedEvent()) { TargetDimension = 100 })
     using (var file = MakeTempPNGImage(10,10))
     {
         using (var img = ImageUtils.GetImageFromFile(cache.GetPathToResizedImage(file.Path)))
         {
             Assert.AreEqual(10, img.Width);
         }
     }
 }
All Usage Examples Of Bloom.ImageProcessing.RuntimeImageProcessor::GetPathToResizedImage