Image Batch Processing...

Janchu88

Kapitän zur See , HWLUXX Vize-Superstar
Thread Starter
Mitglied seit
29.11.2005
Beiträge
5.277
Ort
irgendwo im Nirvana...
Hi, hab ein kleines Tool geschrieben das 3 Dinge kann...

1. Umbenennen von bildern
2. Ein Label setzen (schriftzug der das bild quasi "branded" - auch transparent)
3. Resizen

Das ganze dann halt batchmäßig

Wer interesse dran hat: download

Bin für verbesserungsvorschläge gerne offen... ebenso bin ich an eurer Meinung interessiert

mfG Janchu88
 
Zuletzt bearbeitet:
Wenn Du diese Anzeige nicht sehen willst, registriere Dich und/oder logge Dich ein.
werden die Bilder nach dem resizen auch geschärft? Denn Bilder verlieren stark an Schärfe durchs resizen.
 
noch nicht... aber evtl bald schon... :)

Hab mit dem Projekt erst gestern Abend angefangen, deswegen ist alles noch recht jungfräulich... aber schärfen wäre echt nicht verkehrt.
 
funktioniert Prima.

Schade ist das die Label nur einfarbig gehen.

als kleine Ergänzung (keine Verbesserung) täte ich dir vorschlagen, die gängigsten Bildergrößen bereits als Auswahl anzugeben.
Falls möglich.

lg Akba
 
Label farbe ändern ist eine gute Idee!

die gängisten größen vorzugeben muss ich sehen wie das vernünftig realisierbar wäre, soll aber auch net das Problem sein...

Ich sammel ma nochn bsichen, heute Abend sollte es ein kleines erstes Update geben!
 
Habs noch nicht getestet, finds aber ne gute idee.
Auch wenn ich glaube dass es solche Tools bereits ausreichend gibt.
Ich selbst hab mir auch mal sowas in PHP geschrieben, um schnell Thumbnails von Bildern erstellen zu können. Oder sonst größe und Qualität zu bearbeiten.
Dabei war für mich wichtig, die Qualität der JPGs (10%-100%) mit angeben zu können, um die Dateigröße (Ladezeiten) zu drücken.
Falls du sowas noch nicht berücksichtigt hast, kannst es ja noch mit aufnehmen (Qualität: Sehr gut, gut, mittel, niedrig)...
 
die is derzeit Extremst Chaotisch aufgebaut... einst war es nur ein sehr kleines tool das ich jetzt extrem erweitert habe... ohne spezielle klassen etc... also wirklich extremes wirrwarr... aber ok :fresse:

Form1.cs
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        string[] Pfad;
        string ordner;

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
                openFileDialog1.Multiselect = true;
                openFileDialog1.Filter = "Photo files (*.jpg)|*.jpg|All files (*.*)|*.*";
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    Pfad = openFileDialog1.FileNames;
                }

                if (Pfad != null)
                {
                    for (int i = 0; i < Pfad.Length; i++)
                    {
                        if (liste.Items.Contains(Pfad[i]))
                        {
                        }
                        else
                        {
                            liste.Items.Add(Pfad[i]);
                        }
                    }
                }
            }

            catch(Exception ee)
            {
                MessageBox.Show(ee.ToString());
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int items = liste.Items.Count;
            int errors = 0;         
            string name = outputnametextbox.Text;
            bool eingabe = pruefeEingabe(name);

            if (eingabe == false)
            {
                MessageBox.Show("Output Name contains illegal chars! Please use only 0-9 and A-Z");
            }

            bool label = labelcheckbox.Checked;
            string schriftzug = "";
            int x = 1;
            int y = 1;
            int transparenz = 0;

            

            if (label)
            {
                schriftzug = labeltextbox.Text;
                if (schriftzug.Length < 1)
                {
                    MessageBox.Show("Please define a label or uncheck the label function!");
                    eingabe = false;
                }

                transparenz = 255 - Convert.ToInt32(Convert.ToDouble(labeltransparancybar.Value) * 25.5);                
            }
            
            bool resize = resizebox.Checked;

            if (resize)
            {
                try
                {
                    x = Convert.ToInt32(width.Text);                    
                }

                catch (Exception ee)
                {
                    MessageBox.Show("Width has an illegal value. Use only Integer Values!");
                    eingabe = false;
                }

                try
                {
                    y = Convert.ToInt32(height.Text);
                }

                catch (Exception ee)
                {
                    MessageBox.Show("Height has an illegal Value. Use only Integer Values!");
                    eingabe = false;
                }
            }

            string output = directory.Text;

            if (eingabe)
            {
                for (int i = 0; i < items; i++)
                {
                    try
                    {
                        int höhe;
                        int breite;
                        Bitmap bmp = new Bitmap(liste.Items[i].ToString());
                        höhe = bmp.Height;
                        breite = bmp.Width;
                        Graphics bmpx = Graphics.FromImage(bmp);

                        if (label)
                        {
                            Font font = new Font("Arial", höhe / 5, FontStyle.Bold, GraphicsUnit.Pixel);
                            Point point = new Point();
                            point.X = breite / 10;
                            point.Y = Convert.ToInt32(Convert.ToDouble(höhe) * 0.40);
                            SolidBrush brush = new SolidBrush(Color.FromArgb(transparenz, 128, 128, 128));
                            bmpx.DrawString(schriftzug, font, brush, point);
                        }

                        if (resize)
                        {
                            bmp = ResizeBitmap(bmp, x, y);
                        }
                        
                        if (System.IO.File.Exists(output + "\\" + name + (i + 1) + ".jpg"))
                        {
                            if (MessageBox.Show(output + "\\" + name + (i + 1) + ".jpg already exists, overwrite?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                bmp.Save(output + "\\" + name + (i + 1) + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                            }

                            else
                            {
                                errors += 1;
                            }
                        }

                        else
                        {
                            bmp.Save(output + "\\" + name + (i + 1) + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                        }

                        progressBar1.Value = Convert.ToInt32((Convert.ToDouble(i + 1) / Convert.ToDouble(items)) * 100.0);
                    }

                    catch (Exception ee)
                    {
                        MessageBox.Show(liste.Items[i].ToString() + " could not be processed, reason: " + ee.Message);
                        errors += 1;
                        progressBar1.Value = Convert.ToInt32((Convert.ToDouble(i + 1) / Convert.ToDouble(items)) * 100.0);
                    }
                }
                                
                MessageBox.Show("Processing finished! Errors: " + errors);
                liste.Items.Clear();
            }

            else
            {
               
            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folder = new FolderBrowserDialog();

            if (folder.ShowDialog() == DialogResult.OK)
            {
                ordner = folder.SelectedPath;
                directory.Text = ordner;
            }
        }

        private bool pruefeEingabe(string tmp)
        {
            string pat = "0123456789abcdefghijklmnopqrstuvwABCDEFGHIJKLMNOPQRSTUVWXYZ";
            foreach (char ch in tmp)
            {
                if (pat.IndexOf(ch) < 0)
                    return false;
            }
            return true;
        }

        private void liste_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            labeltextbox.ReadOnly = true;
            labeltransparancybar.Enabled = false;
            width.ReadOnly = true;
            height.ReadOnly = true;
            width.BackColor = Color.LightGray;            
            height.BackColor = Color.LightGray;
            labeltextbox.BackColor = Color.LightGray;
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (labelcheckbox.Checked == true)
            {
                labeltextbox.ReadOnly = false;
                labeltextbox.BackColor = Color.White;
                labeltransparancybar.Enabled = true;
            }
                
            else
            {
                labeltextbox.ReadOnly = true;                
                labeltransparancybar.Enabled = false;
                labeltextbox.BackColor = Color.LightGray;
            }

        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (resizebox.Checked)
            {
                width.ReadOnly = false;
                width.BackColor = Color.White;
                height.ReadOnly = false;
                height.BackColor = Color.White;
            }

            else
            {
                width.ReadOnly = true;
                width.BackColor = Color.LightGray;
                height.ReadOnly = true;
                height.BackColor = Color.LightGray;
            }
        }

        public Bitmap ResizeBitmap(Bitmap b, int nWidth, int nHeight)
        {
            Bitmap result = new Bitmap(nWidth, nHeight);
            using (Graphics g = Graphics.FromImage((Image)result))
            g.DrawImage(b, 0, 0, nWidth, nHeight);
            return result;
        }

        
    }
}

Form1.Designer.cs
Code:
namespace WindowsApplication2
{
    partial class Form1
    {
        /// <summary>
        /// Erforderliche Designervariable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Verwendete Ressourcen bereinigen.
        /// </summary>
        /// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Vom Windows Form-Designer generierter Code

        /// <summary>
        /// Erforderliche Methode für die Designerunterstützung.
        /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
        /// </summary>
        private void InitializeComponent()
        {
            this.addphotos = new System.Windows.Forms.Button();
            this.liste = new System.Windows.Forms.ListBox();
            this.button2 = new System.Windows.Forms.Button();
            this.progressBar1 = new System.Windows.Forms.ProgressBar();
            this.label1 = new System.Windows.Forms.Label();
            this.outputnametextbox = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.Changedirectory = new System.Windows.Forms.Button();
            this.directory = new System.Windows.Forms.Label();
            this.labeltransparancybar = new System.Windows.Forms.TrackBar();
            this.label4 = new System.Windows.Forms.Label();
            this.labeltextbox = new System.Windows.Forms.TextBox();
            this.label5 = new System.Windows.Forms.Label();
            this.resizebox = new System.Windows.Forms.CheckBox();
            this.labelcheckbox = new System.Windows.Forms.CheckBox();
            this.trackBar2 = new System.Windows.Forms.TrackBar();
            this.label6 = new System.Windows.Forms.Label();
            this.label7 = new System.Windows.Forms.Label();
            this.width = new System.Windows.Forms.TextBox();
            this.height = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.labeltransparancybar)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar2)).BeginInit();
            this.SuspendLayout();
            // 
            // addphotos
            // 
            this.addphotos.Location = new System.Drawing.Point(287, 5);
            this.addphotos.Name = "addphotos";
            this.addphotos.Size = new System.Drawing.Size(81, 23);
            this.addphotos.TabIndex = 0;
            this.addphotos.Text = "Add Photos";
            this.addphotos.UseVisualStyleBackColor = true;
            this.addphotos.Click += new System.EventHandler(this.button1_Click);
            // 
            // liste
            // 
            this.liste.FormattingEnabled = true;
            this.liste.Location = new System.Drawing.Point(8, 34);
            this.liste.Name = "liste";
            this.liste.Size = new System.Drawing.Size(617, 173);
            this.liste.TabIndex = 1;
            this.liste.SelectedIndexChanged += new System.EventHandler(this.liste_SelectedIndexChanged);
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(476, 315);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(153, 53);
            this.button2.TabIndex = 2;
            this.button2.Text = "Start";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // progressBar1
            // 
            this.progressBar1.Location = new System.Drawing.Point(15, 399);
            this.progressBar1.Name = "progressBar1";
            this.progressBar1.Size = new System.Drawing.Size(610, 23);
            this.progressBar1.TabIndex = 3;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(12, 225);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(73, 13);
            this.label1.TabIndex = 4;
            this.label1.Text = "Output Name:";
            // 
            // outputnametextbox
            // 
            this.outputnametextbox.Location = new System.Drawing.Point(104, 222);
            this.outputnametextbox.Name = "outputnametextbox";
            this.outputnametextbox.Size = new System.Drawing.Size(525, 20);
            this.outputnametextbox.TabIndex = 5;
            this.outputnametextbox.Text = "picture";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(12, 254);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(85, 13);
            this.label2.TabIndex = 6;
            this.label2.Text = "Output directory:";
            // 
            // Changedirectory
            // 
            this.Changedirectory.Location = new System.Drawing.Point(476, 249);
            this.Changedirectory.Name = "Changedirectory";
            this.Changedirectory.Size = new System.Drawing.Size(153, 23);
            this.Changedirectory.TabIndex = 7;
            this.Changedirectory.Text = "Change directory";
            this.Changedirectory.UseVisualStyleBackColor = true;
            this.Changedirectory.Click += new System.EventHandler(this.button3_Click);
            // 
            // directory
            // 
            this.directory.AutoSize = true;
            this.directory.Location = new System.Drawing.Point(103, 254);
            this.directory.Name = "directory";
            this.directory.Size = new System.Drawing.Size(17, 13);
            this.directory.TabIndex = 8;
            this.directory.Text = "C:";
            // 
            // labeltransparancybar
            // 
            this.labeltransparancybar.Location = new System.Drawing.Point(83, 348);
            this.labeltransparancybar.Name = "labeltransparancybar";
            this.labeltransparancybar.Size = new System.Drawing.Size(104, 45);
            this.labeltransparancybar.TabIndex = 9;
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(12, 325);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(39, 13);
            this.label4.TabIndex = 10;
            this.label4.Text = "Label: ";
            // 
            // labeltextbox
            // 
            this.labeltextbox.Location = new System.Drawing.Point(87, 322);
            this.labeltextbox.Name = "labeltextbox";
            this.labeltextbox.Size = new System.Drawing.Size(100, 20);
            this.labeltextbox.TabIndex = 11;
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(12, 351);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(75, 13);
            this.label5.TabIndex = 12;
            this.label5.Text = "Transparency:";
            // 
            // resizebox
            // 
            this.resizebox.AutoSize = true;
            this.resizebox.Location = new System.Drawing.Point(310, 299);
            this.resizebox.Name = "resizebox";
            this.resizebox.Size = new System.Drawing.Size(58, 17);
            this.resizebox.TabIndex = 17;
            this.resizebox.Text = "Resize";
            this.resizebox.UseVisualStyleBackColor = true;
            this.resizebox.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
            // 
            // labelcheckbox
            // 
            this.labelcheckbox.AutoSize = true;
            this.labelcheckbox.Location = new System.Drawing.Point(104, 299);
            this.labelcheckbox.Name = "labelcheckbox";
            this.labelcheckbox.Size = new System.Drawing.Size(67, 17);
            this.labelcheckbox.TabIndex = 18;
            this.labelcheckbox.Text = "Set label";
            this.labelcheckbox.UseVisualStyleBackColor = true;
            this.labelcheckbox.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
            // 
            // trackBar2
            // 
            this.trackBar2.Location = new System.Drawing.Point(-19, -43);
            this.trackBar2.Name = "trackBar2";
            this.trackBar2.Size = new System.Drawing.Size(104, 45);
            this.trackBar2.TabIndex = 19;
            // 
            // label6
            // 
            this.label6.AutoSize = true;
            this.label6.Location = new System.Drawing.Point(227, 325);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(58, 13);
            this.label6.TabIndex = 20;
            this.label6.Text = "Width(px): ";
            // 
            // label7
            // 
            this.label7.AutoSize = true;
            this.label7.Location = new System.Drawing.Point(227, 351);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(58, 13);
            this.label7.TabIndex = 21;
            this.label7.Text = "Height(px):";
            // 
            // width
            // 
            this.width.Location = new System.Drawing.Point(291, 322);
            this.width.Name = "width";
            this.width.Size = new System.Drawing.Size(100, 20);
            this.width.TabIndex = 22;
            // 
            // height
            // 
            this.height.Location = new System.Drawing.Point(291, 348);
            this.height.Name = "height";
            this.height.Size = new System.Drawing.Size(100, 20);
            this.height.TabIndex = 23;
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(84, 380);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(113, 13);
            this.label3.TabIndex = 24;
            this.label3.Text = " 0%                     100%";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(641, 434);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.height);
            this.Controls.Add(this.width);
            this.Controls.Add(this.label7);
            this.Controls.Add(this.label6);
            this.Controls.Add(this.trackBar2);
            this.Controls.Add(this.labelcheckbox);
            this.Controls.Add(this.resizebox);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.labeltextbox);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.labeltransparancybar);
            this.Controls.Add(this.directory);
            this.Controls.Add(this.Changedirectory);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.outputnametextbox);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.progressBar1);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.liste);
            this.Controls.Add(this.addphotos);
            this.Name = "Form1";
            this.Text = "Image Batch´el0r";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.labeltransparancybar)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar2)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Button addphotos;
        private System.Windows.Forms.ListBox liste;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.ProgressBar progressBar1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.TextBox outputnametextbox;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Button Changedirectory;
        private System.Windows.Forms.Label directory;
        private System.Windows.Forms.TrackBar labeltransparancybar;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.TextBox labeltextbox;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.CheckBox resizebox;
        private System.Windows.Forms.CheckBox labelcheckbox;
        private System.Windows.Forms.TrackBar trackBar2;
        private System.Windows.Forms.Label label6;
        private System.Windows.Forms.Label label7;
        private System.Windows.Forms.TextBox width;
        private System.Windows.Forms.TextBox height;
        private System.Windows.Forms.Label label3;



    }
}

Program.cs
Code:
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace WindowsApplication2
{
    static class Program
    {
        /// <summary>
        /// Der Haupteinstiegspunkt für die Anwendung.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

bitteschön, aber nicht lünchen ... :fresse:
 
ich binn grad auf den thread hier gestoßen.
schöne sache das ganze, leider fehlt mir noch was:
die möglichkeit die höhe des bildes automatisch so auswählen zu lassen, dass es seine proportionen behält
will man ein 1000x800px bild auf 500px breite bringen soll die höhe automatisch auf 800*1000/500=800*0,5=400 pixel gebracht werden

(ansonsten kleinigkeiten wie drag&drop um die elemente hinzuzufügen, set output directory = input directory und output name = input name + belibigen string)

freu mich auf die neue version, wenn es denn eine geben wird :wink:

@selected: ich hab mal einen für dich gemacht:

imageresiz0r.jpg
 
Hardwareluxx setzt keine externen Werbe- und Tracking-Cookies ein. Auf unserer Webseite finden Sie nur noch Cookies nach berechtigtem Interesse (Art. 6 Abs. 1 Satz 1 lit. f DSGVO) oder eigene funktionelle Cookies. Durch die Nutzung unserer Webseite erklären Sie sich damit einverstanden, dass wir diese Cookies setzen. Mehr Informationen und Möglichkeiten zur Einstellung unserer Cookies finden Sie in unserer Datenschutzerklärung.


Zurück
Oben Unten refresh