Quantcast
Channel: magick Discussions Rss Feed
Viewing all articles
Browse latest Browse all 3693

New Post: update tags/keywords in all (xmp, exif, iptc) profiles..

$
0
0
nuget Magick.NET-q16-anyCPU version 6.8.9.601

greetings...as the title suggest, i am trying to update all the "tags/keywords" for a given jpg...

my implementation does not give any errors, but the properties of the jpg remain unchanged- that is if i rightclick>properties the jpeg and inspect the details tag, neither the keywords not the tile are updated...

is there some final "commit" or "save" that i have to perform to make the profile apply?

thanks in advance.
private void button1_Click(object sender, EventArgs e)
        {
            var result = folderBrowserDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                // select the "parent folder" that contains all the subfolders, that contains images w/in...
                foreach (var path in Directory.EnumerateDirectories(folderBrowserDialog1.SelectedPath))
                {
                    // get the current folder in loop.......
                    var folderInfo = new FileInfo(path);

                    foreach (var jpeg in Directory.EnumerateFiles(path, "*.jpg"))
                    {
                        try
                        {
                            // set the "keyWord" to the first 8 characters of the folder that "this" image is in...
                            var keyWord = folderInfo.Name.Substring(0, 8);

                            //AddTags(jpeg, tagSet);
                            UseMagick(jpeg, keyWord);
                        }
                        catch (Exception ex)
                        {
                            // write exception handler 
                        }
                    }
                }
            }
        }

        private void UseMagick(string imagePath, string keyWord)
        {
            using (ImageMagick.MagickImage image = new ImageMagick.MagickImage(imagePath))
            {
                IptcProfile updatedIptcProfile;
                ExifProfile updatedExifProfile;

                // attempt to get the profile(s)...
                updatedIptcProfile = image.GetIptcProfile();
                updatedExifProfile = image.GetExifProfile();

                // if the profile(s) are null, create a new one; otherwise use existing profile data...
                updatedIptcProfile = (updatedIptcProfile == null ? new IptcProfile() : updatedIptcProfile);
                updatedExifProfile = (updatedExifProfile == null ? new ExifProfile() : updatedExifProfile);

                // update the various stuff
                updatedIptcProfile.SetValue(IptcTag.Title, "Testing Adding Title");
                updatedIptcProfile.SetValue(IptcTag.Keyword, keyWord);
                updatedIptcProfile.SetValue(IptcTag.Caption, "image magick");

                image.AddProfile(updatedIptcProfile);

                var updatedProfile = image.GetIptcProfile();
            }
        }

Viewing all articles
Browse latest Browse all 3693

Trending Articles