/// <summary>The create sprited images.</summary> /// <param name="mapXmlFile">The map xml file.</param> /// <param name="imageAssemblyAnalysisLog">The image assembly analysis log.</param> /// <param name="imageReferencesToAssemble">The image references to assemble.</param> /// <param name="cacheSection">The cache section.</param> /// <param name="results">The results.</param> /// <param name="threadContext">The thread Context.</param> /// <returns>The <see cref="bool"/>.</returns> private ImageLog CreateSpritedImages( string mapXmlFile, ImageAssemblyAnalysisLog imageAssemblyAnalysisLog, IEnumerable <InputImage> imageReferencesToAssemble, ICacheSection cacheSection, BlockingCollection <ContentItem> results, IWebGreaseContext threadContext) { if (!Directory.Exists(this.ImagesOutputDirectory)) { Directory.CreateDirectory(this.ImagesOutputDirectory); } var imageMap = ImageAssembleGenerator.AssembleImages( imageReferencesToAssemble.ToSafeReadOnlyCollection(), SpritePackingType.Vertical, this.ImagesOutputDirectory, string.Empty, true, threadContext, this.ImageAssemblyPadding, imageAssemblyAnalysisLog, this.ForcedSpritingImageType); if (imageMap == null || imageMap.Document == null) { return(null); } var destinationDirectory = threadContext.Configuration.DestinationDirectory; if (!string.IsNullOrWhiteSpace(this.ImageAssembleScanDestinationFile)) { var scanXml = imageMap.Document.ToString(); FileHelper.WriteFile(mapXmlFile, scanXml); cacheSection.AddResult(ContentItem.FromFile(mapXmlFile), CacheFileCategories.SpriteLogFileXml); } var imageLog = new ImageLog(imageMap.Document); cacheSection.AddResult(ContentItem.FromContent(imageLog.ToJson(true)), CacheFileCategories.SpriteLogFile); foreach (var spritedFile in imageLog.InputImages.Select(il => il.OutputFilePath).Distinct()) { var spritedImageContentItem = ContentItem.FromFile(spritedFile, spritedFile.MakeRelativeToDirectory(destinationDirectory)); results.Add(spritedImageContentItem); cacheSection.AddResult(spritedImageContentItem, CacheFileCategories.HashedSpriteImage); } return(imageLog); }
public void SeparateByImageTypeTest() { string[] fileNames = { "InputImages\\new\\NotSupported\\AnimatedGIF.GIF", "InputImages\\new\\NotSupported\\MultiFrameTIF.TIF", "InputImages\\new\\NotSupported\\MisnamedTextFile.png", "InputImages\\new\\NotSupported\\CorruptPNG.png", "InputImages\\new\\Photo\\Grayscale8bppJPG.jpg", "InputImages\\new\\Photo\\MisnamedJPG", "InputImages\\new\\Photo\\MisnamedJPG.GIF", "InputImages\\new\\Photo\\MisnamedJPG.PNG", "InputImages\\new\\Photo\\Photo.JPG", "InputImages\\new\\NonphotoNonindexed\\Nonindexed24bppBMP.BMP", "InputImages\\new\\NonphotoNonindexed\\Nonindexed32bppAlphaPNG.png", "InputImages\\new\\NonphotoNonindexed\\Nonindexed32bppPNG.png", "InputImages\\new\\NonphotoIndexed\\Indexable24bppPNG.png", "InputImages\\new\\NonphotoIndexed\\Indexable32bppPNG.png", "InputImages\\new\\NonphotoIndexed\\Indexable32bppPNG256Pixels.png", "InputImages\\new\\NonphotoIndexed\\Indexed1bppBMP.bmp", "InputImages\\new\\NonphotoIndexed\\Indexed2bppPNG.PNG", "InputImages\\new\\NonphotoIndexed\\Indexed4bppBMP.bmp", "InputImages\\new\\NonphotoIndexed\\Indexed4bppPNG.PNG", "InputImages\\new\\NonphotoIndexed\\Indexed8bppBMP.bmp", "InputImages\\new\\NonphotoIndexed\\Indexed8bppGIF.GIF", "InputImages\\new\\NonphotoIndexed\\MisnamedBMP.JPG", "InputImages\\new\\NonphotoIndexed\\MisnamedGIF.EXE", "InputImages\\new\\NonphotoIndexed\\MisnamedGIF.JPG", "InputImages\\new\\NonphotoIndexed\\MisnamedGIF.JS", "InputImages\\new\\NonphotoIndexed\\MisnamedGIF.PNG", "InputImages\\new\\NonphotoIndexed\\MisnamedPNG.BMP", "InputImages\\new\\NonphotoIndexed\\MisnamedPNG.GIF", "InputImages\\new\\NonphotoIndexed\\MisnamedPNG.JPG", "InputImages\\new\\NonphotoIndexed\\SingleFrame.tif" }; string[] expectedFileNamesNotSupported = { "InputImages\\new\\NotSupported\\AnimatedGIF.GIF", "InputImages\\new\\NotSupported\\MultiFrameTIF.TIF", "InputImages\\new\\NotSupported\\MisnamedTextFile.png", "InputImages\\new\\NotSupported\\CorruptPNG.png" }; string[] expectedFileNamesPhoto = { "InputImages\\new\\Photo\\Grayscale8bppJPG.jpg", "InputImages\\new\\Photo\\MisnamedJPG", "InputImages\\new\\Photo\\MisnamedJPG.GIF", "InputImages\\new\\Photo\\MisnamedJPG.PNG", "InputImages\\new\\Photo\\Photo.JPG" }; string[] expectedFileNamesNonphotoNonindexed = { "InputImages\\new\\NonphotoNonindexed\\Nonindexed24bppBMP.BMP", "InputImages\\new\\NonphotoNonindexed\\Nonindexed32bppAlphaPNG.png", "InputImages\\new\\NonphotoNonindexed\\Nonindexed32bppPNG.png" }; string[] expectedFileNamesNonphotoIndexed = { "InputImages\\new\\NonphotoIndexed\\Indexable24bppPNG.png", "InputImages\\new\\NonphotoIndexed\\Indexable32bppPNG.png", "InputImages\\new\\NonphotoIndexed\\Indexable32bppPNG256Pixels.png", "InputImages\\new\\NonphotoIndexed\\Indexed1bppBMP.bmp", "InputImages\\new\\NonphotoIndexed\\Indexed2bppPNG.PNG", "InputImages\\new\\NonphotoIndexed\\Indexed4bppBMP.bmp", "InputImages\\new\\NonphotoIndexed\\Indexed4bppPNG.PNG", "InputImages\\new\\NonphotoIndexed\\Indexed8bppBMP.bmp", "InputImages\\new\\NonphotoIndexed\\Indexed8bppGIF.GIF", "InputImages\\new\\NonphotoIndexed\\MisnamedBMP.JPG", "InputImages\\new\\NonphotoIndexed\\MisnamedGIF.EXE", "InputImages\\new\\NonphotoIndexed\\MisnamedGIF.JPG", "InputImages\\new\\NonphotoIndexed\\MisnamedGIF.JS", "InputImages\\new\\NonphotoIndexed\\MisnamedGIF.PNG", "InputImages\\new\\NonphotoIndexed\\MisnamedPNG.BMP", "InputImages\\new\\NonphotoIndexed\\MisnamedPNG.GIF", "InputImages\\new\\NonphotoIndexed\\MisnamedPNG.JPG", "InputImages\\new\\NonphotoIndexed\\SingleFrame.tif" }; AppendCurrentDirectory(expectedFileNamesNotSupported); AppendCurrentDirectory(expectedFileNamesPhoto); AppendCurrentDirectory(expectedFileNamesNonphotoNonindexed); AppendCurrentDirectory(expectedFileNamesNonphotoIndexed); var expectedFileNames = new Dictionary <WebGrease.ImageAssemble.ImageType, string[]>(); expectedFileNames.Add(WebGrease.ImageAssemble.ImageType.NotSupported, expectedFileNamesNotSupported); expectedFileNames.Add(WebGrease.ImageAssemble.ImageType.Photo, expectedFileNamesPhoto); expectedFileNames.Add(WebGrease.ImageAssemble.ImageType.NonphotoNonindexed, expectedFileNamesNonphotoNonindexed); expectedFileNames.Add(WebGrease.ImageAssemble.ImageType.NonphotoIndexed, expectedFileNamesNonphotoIndexed); var inputImagesList = new List <InputImage>(); foreach (var fileName in fileNames) { inputImagesList.Add(new InputImage(Path.Combine(Environment.CurrentDirectory, fileName))); } var separatedLists = ImageAssembleGenerator.SeparateByImageType(inputImagesList.AsReadOnly()); foreach (ImageType imageType in System.Enum.GetValues(typeof(WebGrease.ImageAssemble.ImageType))) { var separatedList = separatedLists[imageType]; CompareLists(separatedList, expectedFileNames[imageType]); if (separatedList != null) { foreach (var entry in separatedList) { if (entry.Bitmap != null) { entry.Bitmap.Dispose(); } } } } }