public static IList <OptimizedFile> OptimizeImages(this ICakeContext context, DirectoryPath sourceDirectory, DirectoryPath outputDirectory, ImageOptimizerSettings settings)
 {
     return(context.CreateBulkImageOptimizer().Optimize(sourceDirectory, outputDirectory, settings));
 }
        /// <summary>
        /// Optimizes Images from the settings SourceDirectory
        /// </summary>
        /// <param name="sourceDirectory">The directory of the original images.</param>
        /// <param name="outputDirectory">The directory of the optimized images.</param>
        /// <param name="settings">The settings to use when optimizing the images.</param>
        public IList <OptimizedFile> Optimize(DirectoryPath sourceDirectory, DirectoryPath outputDirectory, ImageOptimizerSettings settings)
        {
            DirectoryPath source = sourceDirectory.MakeAbsolute(_Environment);
            DirectoryPath output = outputDirectory.MakeAbsolute(_Environment);

            IDirectory dir = _FileSystem.GetDirectory(source);

            if (dir.Exists)
            {
                FileConfig config = new FileConfig(_FileSystem, _Environment, _Log);
                config.Load(settings.ConfigFile);

                IList <IFile> files = dir.GetFiles(settings.SearchFilter, settings.SearchScope).ToList();

                IList <OptimizedFile> results = this.Optimize("", source, output, files, config.Files);

                config.AddResults(results);
                config.Save(settings.ConfigFile);

                return(results);
            }
            else
            {
                throw new Exception("The source directory does not exist '" + source.FullPath + "'");
            }
        }