WriteVerbose() public static method

public static WriteVerbose ( string message = "" ) : void
message string
return void
Ejemplo n.º 1
0
 public static void SetupPaths(Dictionary <string, Tuple <string, double> > expectedImages, bool dry)
 {
     foreach (
         var path in
         expectedImages.Select(meta => Path.GetDirectoryName(meta.Value.Item1)).Where(path => path != null && !Directory.Exists(path)))
     {
         if (dry)
         {
             LoggingService.WriteVerbose("Would have created directory {0}", path);
         }
         else
         {
             Directory.CreateDirectory(path);
             LoggingService.WriteVerbose("Created directory {0}", path);
         }
     }
 }
Ejemplo n.º 2
0
        public void Process(FileInfo image, string outPath, string prefix, string suffix, ImageFormat format)
        {
            LoggingService.WriteLine("Processing {0}", image.Name);
            var outFileName = string.Format("{0}{1}{2}", prefix, Path.GetFileNameWithoutExtension(image.FullName), suffix);
            var rootDir     = string.IsNullOrWhiteSpace(outPath) ? Path.GetDirectoryName(_here) : new DirectoryInfo(outPath).FullName;
            var extension   = format == null ? image.Extension : string.Format(".{0}", format.ToString().ToLower());

            LoggingService.WriteVerbose("New File Name: {0}{1}", outFileName, extension);


            int defaultHeight;
            int defaultWidth;

            using (var img = Image.FromFile(image.FullName))
            {
                defaultHeight = img.Height;
                defaultWidth  = img.Width;
            }

            LoggingService.WriteVerbose("Original Dimensions: {0}W by {1}H", defaultWidth, defaultHeight);

            var expectedImages = ImageHelper.BuildImageInfo(rootDir, outFileName, extension);

            DirectoryHelper.SetupPaths(expectedImages, _dry);

            var codec = ImageHelper.GetImageCodecInfo(format);

            foreach (var expectedImage in expectedImages)
            {
                var path         = expectedImage.Value.Item1;
                var scale        = expectedImage.Value.Item2;
                var scaledWidth  = (int)Math.Ceiling(defaultWidth / scale);
                var scaledHeight = (int)Math.Ceiling(defaultHeight / scale);
                var scaledImage  = _scalerService.Scale(scaledWidth, scaledHeight, image.FullName);
                scaledImage.Save(path, codec, _dry);

                LoggingService.WriteVerbose("New Dimensions for {0}: {1}W by {2}H", expectedImage.Key, scaledWidth, scaledHeight);
            }
            LoggingService.WriteLine();
        }
Ejemplo n.º 3
0
        private static void Main(string[] args)
        {
            var         helpRequested = false;
            var         log           = false;
            var         verbose       = false;
            var         quiet         = false;
            var         images        = new List <FileInfo>();
            var         outPath       = AppDomain.CurrentDomain.BaseDirectory;
            var         prefix        = string.Empty;
            var         suffix        = string.Empty;
            ImageFormat format        = null;
            var         dry           = false;

            var options = new OptionSet
            {
                {
                    "i|img|image=", "Image to resize \nnote: this MUST be your largest version (xxhdpi/@3x)",
                    v => images.Add(new FileInfo(v))
                },
                {
                    "f|format=", "Output format (png, jpg)",
                    v => format = ImageHelper.ParseImageFormat(v)
                },
                {
                    "o|out|outpath=", "Path to save out the image\ndefaults to current directory of downsize.exe",
                    v => outPath = v
                },
                {
                    "pre|prefix=", "Prefix to prepend to the image name",
                    v => prefix = v
                },
                {
                    "suf|suffix=", "Suffix to append to the image name",
                    v => suffix = v
                },
                {
                    "l|log", "write a log file to the output directory",
                    v => log = v != null
                },
                {
                    "s|q|silent|quiet", "Don't write out to console",
                    v => quiet = v != null
                },
                {
                    "d|dry|dryrun", "Summary of what would happen",
                    v => dry = v != null
                },
                {
                    "v|verbose", "Write verbose information",
                    v => verbose = v != null
                },
                {
                    "?|h|help", "show help message and exit",
                    v => helpRequested = v != null
                }
            };

            try
            {
                var p = options.Parse(args);
                images.AddRange(p.Select(unParsed => new FileInfo(unParsed)));
            }
            catch (OptionException e)
            {
                Console.Write("{0}: ", AppName);
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `{0} --help' for more information.", AppName);
                Console.WriteLine();
                return;
            }

            if (helpRequested)
            {
                ShowHelp(options);
                return;
            }

            LoggingService.Init(outPath, log, verbose, quiet);
            LoggingService.WriteLine("Begin Processing Images!");
            LoggingService.WriteVerbose("Writing files to {0}", outPath);

            var processor = new ImageProcessor(dry);

            foreach (var image in images)
            {
                try
                {
                    processor.Process(image, outPath, prefix, suffix, format);
                }
                catch (Exception ex)
                {
                    LoggingService.WriteError("An error occurred while processing {0}", image);
                    LoggingService.WriteError(ex.Message);
                }
            }
            LoggingService.WriteLine("Finished Processing Images!");
        }