Example #1
0
        static void Main(string[] args)
        {
            try
            {
                string errors = parseArgs(args);
                if (!string.IsNullOrEmpty(errors))
                {
                    Usage(errors);
                    return;
                }

                FolderResizer frs = new FolderResizer
                                        (srcFolder, maxSize, maxWidth, maxHeight, quality);
                frs.OutputFileType = fileFormat;
                frs.ResizeTo(dstFolder, clearOutputFolder);
                if (verbose)
                {
                    Console.WriteLine(frs.CompressionInfo);
                }
            }
            catch (Exception x)
            {
                Usage(x.Message);
            }
        }
        public void CanResizeFilesFromAFolder()
        {
            string tmpFolder = Path.GetTempPath();

            tmpFolder = Path.Combine(tmpFolder, "ImgResizeOutput");
            try
            {
                if (Directory.Exists(tmpFolder))
                {
                    Directory.Delete(tmpFolder, true);
                }
                string currPath = Path.GetFullPath(".");
                var    fr       = new FolderResizer(currPath, 100000, 1024, 768, 66);
                fr.OutputFileType = "JPG";
                fr.ResizeTo(tmpFolder, true);
                Assert.AreEqual(3, Directory.GetFiles(tmpFolder).Length);
            }
            finally
            {
                if (Directory.Exists(tmpFolder))
                {
                    Directory.Delete(tmpFolder, true);
                }
            }
        }
Example #3
0
        private async void btnShrink_Click(object sender, EventArgs e)
        {
            if (Path.GetFullPath(lblDestDir.Text) == Path.GetFullPath(lblSourceDir.Text))
            {
                if (MessageBox.Show(this, "Origin and destination folder are the same. Click 'OK'"
                                    + " to put the shrunken files into  'Shrunk' subfolder of origin"
                                    + " folder, or 'Cancel' to choose another folder", "Folders must be different",
                                    MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    lblDestDir.Text = Path.Combine(lblDestDir.Text, "Shrunk");
                }
            }

            if (!Directory.Exists(lblDestDir.Text))
            {
                try
                {
                    Directory.CreateDirectory(lblDestDir.Text);
                    Directory.Delete(lblDestDir.Text);
                }
                catch (Exception x)
                {
                    MessageBox.Show(this, "Cannot create destination folder "
                                    + lblDestDir.Text + ", (" + x.Message + ")",
                                    "Incorrect destination folder", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
            }

            Cursor oldCursor = Cursor;

            Cursor = Cursors.WaitCursor;
            SaveSettings();
            string format = ddlFormat.SelectedItem.ToString();
            await Task.Run(() =>
            {
                frs = new FolderResizer
                          (Properties.Settings.Default.SrcFolder,
                          Properties.Settings.Default.MaxSize * 1024,
                          Properties.Settings.Default.MaxWidth,
                          Properties.Settings.Default.MaxHeight,
                          Properties.Settings.Default.Quality);
                frs.OutputFileType = format;
                frs.Notifier       = UpdateProgress;
                frs.ResizeTo(Properties.Settings.Default.DstFolder, chkClearOutputFolder.Checked);
            });

            tsProgress.Value     = 0;
            tsProgressLabel.Text = string.Empty;
            Cursor = oldCursor;
        }
Example #4
0
        private async void btnShrink_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(lblDestDir.Text))
            {
                try
                {
                    Directory.CreateDirectory(lblDestDir.Text);
                    Directory.Delete(lblDestDir.Text);
                }
                catch (Exception x)
                {
                    MessageBox.Show(this, "Cannot create destination folder "
                                    + lblDestDir.Text + ", (" + x.Message + ")",
                                    "Incorrect destination folder", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
            }

            Cursor oldCursor = Cursor;

            Cursor = Cursors.WaitCursor;
            SaveSettings();
            string format = ddlFormat.SelectedItem.ToString();
            await Task.Run(() =>
            {
                frs = new FolderResizer
                          (Properties.Settings.Default.SrcFolder,
                          Properties.Settings.Default.MaxSize * 1024,
                          Properties.Settings.Default.MaxWidth,
                          Properties.Settings.Default.MaxHeight,
                          Properties.Settings.Default.Quality);
                frs.OutputFileType = format;
                frs.Notifier       = UpdateProgress;
                frs.ResizeTo(Properties.Settings.Default.DstFolder, chkClearOutputFolder.Checked);
            });

            tsProgress.Value     = 0;
            tsProgressLabel.Text = string.Empty;
            Cursor = oldCursor;
        }