Example #1
0
        public static void PerformImageResizeAndPutOnCanvas(string pFilePath, string pFileName, int pWidth, int pHeight, string pOutputFileName, string destPath)
        {
            System.Drawing.Image imgBef;
            imgBef = System.Drawing.Image.FromFile(pFilePath + pFileName);


            System.Drawing.Image _imgR;
            _imgR = Imager.Resize(imgBef, pWidth, pHeight, true);


            System.Drawing.Image _img2;
            _img2 = Imager.PutOnCanvas(_imgR, pWidth, pHeight, System.Drawing.Color.White);

            //Save JPEG
            Imager.SaveJpeg(destPath + pOutputFileName, _img2);

            imgBef.Dispose();
            _imgR.Dispose();
            _img2.Dispose();
        }
Example #2
0
        static void Main(string[] args)
        {
            Console.Title = "Resize Image - " + ver;

            string[] filePaths = Directory.GetFiles(sourcePath, "*.jpg");

            string[] directories = new string[] { sourcePath, destinationPath, processedPath };

            foreach (string dir in directories)
            {
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
            }

            if (args.Length > 1)
            {
                if (args[0].Contains("square"))
                {
                    int number;

                    bool result = Int32.TryParse(args[1], out number);
                    if (result)
                    {
                        resizeWidthPixel = resizeHeightPixel = Convert.ToInt32(args[1]);
                    }
                }
            }


            Console.WriteLine("Resize resolution: Height: " + resizeHeightPixel + " - Width: " + resizeWidthPixel + ". Are you OK with this or not? Anykey = Yes / N = No ");
            if (Console.ReadLine().ToLower() == "n")
            {
                int enterHeight = 0;
                while (enterHeight > 4000 || enterHeight < 50)
                {
                    Console.WriteLine("Enter Resize Height in px (max 4000px - min: 50px): ");
                    enterHeight = Convert.ToInt32(Console.ReadLine());
                }

                int enterWidth = 0;
                while (enterWidth > 4000 || enterWidth < 50)
                {
                    Console.WriteLine("Enter Resize Width in px (max 4000px - min: 50px): ");
                    enterWidth = Convert.ToInt32(Console.ReadLine());
                }
                resizeHeightPixel = enterHeight;
                resizeWidthPixel  = enterWidth;
            }



            try
            {
                if (filePaths.Length > 0)
                {
                    foreach (string imgPath in filePaths)
                    {
                        string fileName = Path.GetFileName(imgPath);

                        string newFileName = fileName + "_" + resizeWidthPixel + "_" + resizeHeightPixel + ".jpg";

                        Imager.PerformImageResizeAndPutOnCanvas(sourcePath, fileName, resizeWidthPixel, resizeHeightPixel, newFileName, destinationPath);

                        MoveFile(imgPath, processedPath + fileName);

                        Console.WriteLine(fileName + " - Resized");
                    }
                    Console.WriteLine("All images in " + sourcePath + " are resized and save in " + destinationPath + " successfully!");
                }
                else
                {
                    Console.WriteLine("No images found!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: " + ex.Message);
            }
            Console.WriteLine("Press any key to EXIT program.");
            Console.ReadLine();
        }