Exemplo n.º 1
0
        public void ShouldBeAbleToReadAndWriteIptcValues()
        {
            using (IMagickImage input = new MagickImage(Files.MagickNETIconPNG))
            {
                IptcProfile profile = input.GetIptcProfile();
                Assert.IsNull(profile);

                profile = new IptcProfile();
                profile.SetValue(IptcTag.Headline, "Magick.NET");
                profile.SetValue(IptcTag.CopyrightNotice, "Copyright.NET");

                input.AddProfile(profile);

                using (MemoryStream memStream = new MemoryStream())
                {
                    input.Format = MagickFormat.Tiff;
                    input.Write(memStream);

                    memStream.Position = 0;
                    using (IMagickImage output = new MagickImage(memStream))
                    {
                        profile = output.GetIptcProfile();
                        Assert.IsNotNull(profile);
                        TestValue(profile, IptcTag.Headline, "Magick.NET");
                        TestValue(profile, IptcTag.CopyrightNotice, "Copyright.NET");
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static void TestValue(IptcProfile profile, IptcTag tag, string expectedValue)
        {
            IptcValue value = profile.GetValue(tag);

            Assert.IsNotNull(value);
            Assert.AreEqual(expectedValue, value.Value);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes the IPTC profile.
 /// </summary>
 private void InitIptcProfile()
 {
     if (this.isIptc)
     {
         var profile = new IptcProfile(this.iptcData);
         this.Metadata.IptcProfile = profile;
     }
 }
Exemplo n.º 4
0
 private static IptcValue GetIptcValue()
 {
     using (IMagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
     {
         IptcProfile profile = image.GetIptcProfile();
         return(profile.Values.ElementAt(1));
     }
 }
Exemplo n.º 5
0
            public void ShouldThrowExceptionWhenTagIsNotDateOrTime()
            {
                var profile  = new IptcProfile();
                var datetime = new DateTimeOffset(new DateTime(1994, 3, 17));

                Assert.Throws <ArgumentException>("tag", () =>
                {
                    profile.SetValue(IptcTag.ActionAdvised, datetime);
                });
            }
Exemplo n.º 6
0
 public void ReadIptcMetadata_FromTiff_Works <TPixel>(TestImageProvider <TPixel> provider)
     where TPixel : unmanaged, IPixel <TPixel>
 {
     using (Image <TPixel> image = provider.GetImage(TiffDecoder))
     {
         IptcProfile iptc = image.Frames.RootFrame.Metadata.IptcProfile;
         Assert.NotNull(iptc);
         var iptcValues = iptc.Values.ToList();
         IptcProfileContainsExpectedValues(iptcValues);
     }
 }
Exemplo n.º 7
0
        private static void TestProfileValues(IptcProfile profile, int count)
        {
            Assert.IsNotNull(profile);

            Assert.AreEqual(count, profile.Values.Count());

            foreach (IptcValue value in profile.Values)
            {
                Assert.IsNotNull(value.Value);
            }
        }
Exemplo n.º 8
0
            public void ShouldFormatTheDate(IptcTag tag)
            {
                var profile  = new IptcProfile();
                var datetime = new DateTimeOffset(new DateTime(1994, 3, 17));

                profile.SetValue(tag, datetime);

                var actual = profile.GetValue(tag);

                Assert.Equal("19940317", actual.Value);
            }
            public void ShouldOnlyRemoveTheValueWithTheSpecifiedValue()
            {
                var profile = new IptcProfile();

                profile.SetValue(IptcTag.Byline, "test");
                profile.SetValue(IptcTag.Byline, "test2");

                var result = profile.RemoveValue(IptcTag.Byline, "test2");

                Assert.IsTrue(result);
                Assert.IsTrue(profile.Values.Contains(new IptcValue(IptcTag.Byline, Encoding.UTF8.GetBytes("test"))));
            }
Exemplo n.º 10
0
            public void ShouldRemoveAllValues()
            {
                var profile = new IptcProfile();

                profile.SetValue(IptcTag.Byline, "test");
                profile.SetValue(IptcTag.Byline, "test2");

                var result = profile.RemoveValue(IptcTag.Byline);

                Assert.IsTrue(result);
                Assert.AreEqual(0, profile.Values.Count());
            }
Exemplo n.º 11
0
            public void ShouldFormatTheTime(IptcTag tag)
            {
                var profile        = new IptcProfile();
                var dateTimeUtc    = new DateTime(1994, 3, 17, 14, 15, 16, DateTimeKind.Utc);
                var dateTimeOffset = new DateTimeOffset(dateTimeUtc).ToOffset(TimeSpan.FromHours(2));

                profile.SetValue(tag, dateTimeOffset);

                var actual = profile.GetAllValues(tag).First();

                Assert.Equal("161516+0200", actual.Value);
            }
Exemplo n.º 12
0
            public void ShouldRemoveAllValues()
            {
                var profile = new IptcProfile();

                profile.SetValue(IptcTag.Byline, "test");
                profile.SetValue(IptcTag.Byline, "test2");

                var result = profile.RemoveValue(IptcTag.Byline);

                Assert.True(result);
                Assert.Empty(profile.Values);
            }
Exemplo n.º 13
0
            public void ShouldReturnAllValues()
            {
                var profile = new IptcProfile();

                profile.SetValue(IptcTag.Byline, "test");
                profile.SetValue(IptcTag.Byline, "test2");
                profile.SetValue(IptcTag.Caption, "test");

                var result = profile.GetAllValues(IptcTag.Byline);

                Assert.NotNull(result);
                Assert.Equal(2, result.Count());
            }
Exemplo n.º 14
0
            public void ShoulNotdAllowDuplicateValuesForValuesThatCannotBeRepated(IptcTag tag)
            {
                var profile       = new IptcProfile();
                var expectedValue = "another one";

                profile.SetValue(tag, "test");
                profile.SetValue(tag, expectedValue);

                var values = profile.Values.ToList();

                Assert.Single(values);
                Assert.Contains(new IptcValue(tag, Encoding.UTF8.GetBytes(expectedValue)), values);
            }
Exemplo n.º 15
0
        public void CanDecodeImage_WithIptcDataAsLong <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            using Image <TPixel> image = provider.GetImage(TiffDecoder);

            IptcProfile iptcProfile = image.Frames.RootFrame.Metadata.IptcProfile;

            Assert.NotNull(iptcProfile);
            IptcValue byline = iptcProfile.Values.FirstOrDefault(data => data.Tag == IptcTag.Byline);

            Assert.NotNull(byline);
            Assert.Equal("Studio Mantyniemi", byline.Value);
        }
Exemplo n.º 16
0
        public void IptcProfile_SetDateValue_Works(IptcTag tag)
        {
            // arrange
            var profile  = new IptcProfile();
            var datetime = new DateTimeOffset(new DateTime(1994, 3, 17));

            // act
            profile.SetDateTimeValue(tag, datetime);

            // assert
            IptcValue actual = profile.GetValues(tag).First();

            Assert.Equal("19940317", actual.Value);
        }
Exemplo n.º 17
0
            public void ShouldAllowDuplicateValuesForValuesThatCanBeRepated(IptcTag tag)
            {
                var profile        = new IptcProfile();
                var expectedValue1 = "test";
                var expectedValue2 = "another one";

                profile.SetValue(tag, expectedValue1);
                profile.SetValue(tag, expectedValue2);

                var values = profile.Values.ToList();

                Assert.Equal(2, values.Count);
                Assert.Contains(new IptcValue(tag, Encoding.UTF8.GetBytes(expectedValue1)), values);
                Assert.Contains(new IptcValue(tag, Encoding.UTF8.GetBytes(expectedValue2)), values);
            }
Exemplo n.º 18
0
        public void IptcProfile_SetValue_WithStrictOption_Works(IptcTag tag)
        {
            // arrange
            var profile        = new IptcProfile();
            var value          = new string('s', tag.MaxLength() + 1);
            var expectedLength = tag.MaxLength();

            // act
            profile.SetValue(tag, value);

            // assert
            IptcValue actual = profile.GetValues(tag).First();

            Assert.Equal(expectedLength, actual.Value.Length);
        }
Exemplo n.º 19
0
        public void IptcProfile_RemoveByTag_RemovesAllEntrys()
        {
            // arange
            var profile = new IptcProfile();

            profile.SetValue(IptcTag.Byline, "test");
            profile.SetValue(IptcTag.Byline, "test2");

            // act
            var result = profile.RemoveValue(IptcTag.Byline);

            // assert
            Assert.True(result, "removed result should be true");
            Assert.Empty(profile.Values);
        }
Exemplo n.º 20
0
        public void IptcProfile_SetTimeValue_Works(IptcTag tag)
        {
            // arrange
            var            profile        = new IptcProfile();
            var            dateTimeUtc    = new DateTime(1994, 3, 17, 14, 15, 16, DateTimeKind.Utc);
            DateTimeOffset dateTimeOffset = new DateTimeOffset(dateTimeUtc).ToOffset(TimeSpan.FromHours(2));

            // act
            profile.SetDateTimeValue(tag, dateTimeOffset);

            // assert
            IptcValue actual = profile.GetValues(tag).First();

            Assert.Equal("161516+0200", actual.Value);
        }
Exemplo n.º 21
0
        public void IptcProfile_RemoveByTagAndValue_Works()
        {
            // arange
            var profile = new IptcProfile();

            profile.SetValue(IptcTag.Byline, "test");
            profile.SetValue(IptcTag.Byline, "test2");

            // act
            var result = profile.RemoveValue(IptcTag.Byline, "test2");

            // assert
            Assert.True(result, "removed result should be true");
            ContainsIptcValue(profile.Values.ToList(), IptcTag.Byline, "test");
        }
Exemplo n.º 22
0
        public void Test_SetEncoding()
        {
            using (IMagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
            {
                IptcProfile profile = image.GetIptcProfile();
                TestProfileValues(profile);

                ExceptionAssert.Throws <ArgumentNullException>(delegate()
                {
                    profile.SetEncoding(null);
                });

                profile.SetEncoding(Encoding.UTF8);
                Assert.AreEqual(Encoding.UTF8, profile.Values.First().Encoding);
            }
        }
Exemplo n.º 23
0
        public void IptcProfile_GetValue_RetrievesAllEntrys()
        {
            // arange
            var profile = new IptcProfile();

            profile.SetValue(IptcTag.Byline, "test");
            profile.SetValue(IptcTag.Byline, "test2");
            profile.SetValue(IptcTag.Caption, "test");

            // act
            List <IptcValue> result = profile.GetValues(IptcTag.Byline);

            // assert
            Assert.NotNull(result);
            Assert.Equal(2, result.Count);
        }
Exemplo n.º 24
0
        public void Test_Values()
        {
            using (IMagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
            {
                IptcProfile profile = image.GetIptcProfile();
                TestProfileValues(profile);

                using (IMagickImage emptyImage = new MagickImage(Files.ImageMagickJPG))
                {
                    Assert.IsNull(emptyImage.GetIptcProfile());
                    emptyImage.AddProfile(profile);

                    profile = emptyImage.GetIptcProfile();
                    TestProfileValues(profile);
                }
            }
        }
Exemplo n.º 25
0
        public void IptcProfile_AddNoneRepeatable_DoesOverrideOldValue(IptcTag tag)
        {
            // arrange
            var profile       = new IptcProfile();
            var expectedValue = "another one";

            profile.SetValue(tag, "test", false);

            // act
            profile.SetValue(tag, expectedValue, false);

            // assert
            var values = profile.Values.ToList();

            Assert.Equal(1, values.Count);
            ContainsIptcValue(values, tag, expectedValue);
        }
Exemplo n.º 26
0
        private static string GetExifDataFromTag(IptcProfile profile, IptcTag tag)
        {
            if (profile == null)
            {
                return(null);
            }

            var outValue = string.Empty;

            try
            {
                outValue = profile.GetValue(tag).Value;
            }
            catch
            {// Wert ist nicht vorhanden / konnte nicht konvertiert werden
            }

            return(outValue);
        }
Exemplo n.º 27
0
        public void IptcProfile_AddRepeatable_Works(IptcTag tag)
        {
            // arrange
            var profile        = new IptcProfile();
            var expectedValue1 = "test";
            var expectedValue2 = "another one";

            profile.SetValue(tag, expectedValue1, false);

            // act
            profile.SetValue(tag, expectedValue2, false);

            // assert
            var values = profile.Values.ToList();

            Assert.Equal(2, values.Count);
            ContainsIptcValue(values, tag, expectedValue1);
            ContainsIptcValue(values, tag, expectedValue2);
        }
        public void Encode_PreservesIptcProfile()
        {
            // arrange
            using var input            = new Image <Rgba32>(1, 1);
            input.Metadata.IptcProfile = new IptcProfile();
            input.Metadata.IptcProfile.SetValue(IptcTag.Byline, "unit_test");

            // act
            using var memStream = new MemoryStream();
            input.Save(memStream, JpegEncoder);

            // assert
            memStream.Position = 0;
            using var output   = Image.Load <Rgba32>(memStream);
            IptcProfile actual = output.Metadata.IptcProfile;

            Assert.NotNull(actual);
            IEnumerable <IptcValue> values = input.Metadata.IptcProfile.Values;

            Assert.Equal(values, actual.Values);
        }
Exemplo n.º 29
0
        public void IptcProfile_ToAndFromByteArray_Works()
        {
            // arrange
            var profile = new IptcProfile();
            var expectedCaptionWriter = "unittest";
            var expectedCaption       = "test";

            profile.SetValue(IptcTag.CaptionWriter, expectedCaptionWriter);
            profile.SetValue(IptcTag.Caption, expectedCaption);

            // act
            profile.UpdateData();
            byte[] profileBytes     = profile.Data;
            var    profileFromBytes = new IptcProfile(profileBytes);

            // assert
            var iptcValues = profileFromBytes.Values.ToList();

            ContainsIptcValue(iptcValues, IptcTag.CaptionWriter, expectedCaptionWriter);
            ContainsIptcValue(iptcValues, IptcTag.Caption, expectedCaption);
        }
Exemplo n.º 30
0
        private static void Metadata(MagickImage image, ImageDetails details)
        {
            var xmp        = MetadataController.Get(details);
            var xmpBuffer  = XmpMetaFactory.SerializeToBuffer(xmp, new SerializeOptions());
            var xmpProfile = new XmpProfile(xmpBuffer);

            image.AddProfile(xmpProfile);

            var iptcProfile = new IptcProfile();

            iptcProfile.SetValue(IptcTag.City, "London");
            iptcProfile.SetValue(IptcTag.Country, "UK");
            iptcProfile.SetValue(IptcTag.Contact, "[email protected], +447740424810,http://www.mcandrewphoto.co.uk");

            iptcProfile.SetValue(IptcTag.CopyrightNotice, "Attribution 3.0 Unported (CC BY 3.0)");
            iptcProfile.SetValue(IptcTag.Title, $"{details.GivenName} {details.FamilyName}");

            iptcProfile.SetValue(IptcTag.Source, "Chris McAndrew / UK Parliament");
            iptcProfile.SetValue(IptcTag.Credit, "Chris McAndrew / UK Parliament (Attribution 3.0 Unported (CC BY 3.0))");

            image.AddProfile(iptcProfile);
        }