Problem of this prog,

1. it doesn't recognize portrait / landscape
2. if params height and width not proportional to original image
thumbnails will look ugly :)

vitaly


2009/9/10 Processor-Dev1l <[email protected]>:
>
> Hi guys. I am just doing a business web page for my friends. Problem
> is they want about 200 pictures into galery (web page is html only)
> and one pic has about 5 MB.
> Because I didn't want to resize each picture I made this simple
> console application, I hope you will find it useful :)
>
> using System;
> using System.IO;
> using System.Drawing;
>
> namespace ThumbNail
> {
>    class Program
>    {
>        static void Main(string[] args)
>        {
>            if (args.Length != 3)
>                Console.WriteLine("Usage:\n ThumbNail <directory>
> <target_width> <target_height>");
>            else
>            {
>                try
>                {
>                    Resizer rsz = new Resizer(args[0], int.Parse(args
> [2]), int.Parse(args[1]));
>                    rsz.ResizeImages();
>                }
>                catch (Exception e)
>                {
>                    Console.WriteLine(e.Message);
>                }
>            }
>        }
>    }
>    class Resizer
>    {
>        public Resizer(string directory, int height, int width)
>        {
>            this.directory = directory;
>            this.height = height;
>            this.width = width;
>        }
>        public void ResizeImages()
>        {
>            string[] files = Directory.GetFiles(this.directory);
>            string newDir = Path.Combine(this.directory,
> "thumbnails");
>            if (!Directory.Exists(newDir))
>                Directory.CreateDirectory(newDir);
>            foreach (string file in files)
>            {
>                Image img = Image.FromFile(file);
>                Image resized = img.GetThumbnailImage(this.width,
> this.height,
>                    new Image.GetThumbnailImageAbort(problem),
> IntPtr.Zero);
>                string newName = string.Format("{0}_t{1}",
>                    Path.GetFileNameWithoutExtension(file),
>                    Path.GetExtension(file));
>                resized.Save(Path.Combine(newDir, newName));
>                Console.WriteLine("{0} --> {1}", Path.GetFileName
> (file), newName);
>            }
>        }
>        bool problem()
>        {
>            Console.WriteLine("Problem with creating a thumbnail");
>            return false;
>        }
>
>        string directory;
>        int height;
>        int width;
>    }
> }

Reply via email to