Exemple #1
0
            public void ShouldAllowNullValues()
            {
                var profile = new ExifProfile();

                profile.SetValue(ExifTag.ReferenceBlackWhite, null);

                var value = profile.GetValue(ExifTag.ReferenceBlackWhite);

                TestValue(value, null);
            }
        public void WriteFraction()
        {
            using (MemoryStream memStream = new MemoryStream())
            {
                double exposureTime = 1.0 / 1600;

                ExifProfile profile = GetExifProfile();

                profile.SetValue(ExifTag.ExposureTime, new Rational(exposureTime));

                Image image = new Image(1, 1);
                image.MetaData.ExifProfile = profile;

                image.SaveAsJpeg(memStream);

                memStream.Position = 0;
                image = Image.Load(memStream);

                profile = image.MetaData.ExifProfile;
                Assert.NotNull(profile);

                ExifValue value = profile.GetValue(ExifTag.ExposureTime);
                Assert.NotNull(value);
                Assert.NotEqual(exposureTime, ((Rational)value.Value).ToDouble());

                memStream.Position = 0;
                profile            = GetExifProfile();

                profile.SetValue(ExifTag.ExposureTime, new Rational(exposureTime, true));
                image.MetaData.ExifProfile = profile;

                image.SaveAsJpeg(memStream);

                memStream.Position = 0;
                image = Image.Load(memStream);

                profile = image.MetaData.ExifProfile;
                Assert.NotNull(profile);

                value = profile.GetValue(ExifTag.ExposureTime);
                Assert.Equal(exposureTime, ((Rational)value.Value).ToDouble());
            }
        }
            public void ShouldReturnFalseWhenValueIsInvalidDataType2()
            {
                var profile = new ExifProfile();

                profile.SetValue(ExifTag.ShutterSpeedValue, new SignedRational(75.55));

                IExifValue value = profile.GetValue(ExifTag.ShutterSpeedValue);

                Assert.False(value.SetValue(75));
            }
Exemple #4
0
            public void ShouldReturnStringWhenValueIsString()
            {
                var profile = new ExifProfile();

                profile.SetValue(ExifTag.Software, "Magick.NET");

                var value = profile.GetValue(ExifTag.Software);

                TestValue(value, "Magick.NET");
            }
Exemple #5
0
        public static void ApplyPreviewImageMagick(string source, string destination, double maxWidth, double maxHeight,
                                                   [CanBeNull] AcPreviewImageInformation information)
        {
            using (var image = new MagickImage(source)) {
                if (maxWidth > 0d || maxHeight > 0d)
                {
                    var k = Math.Max(maxHeight / image.Height, maxWidth / image.Width);
                    image.Interpolate = PixelInterpolateMethod.Catrom;
                    image.FilterType  = FilterType.Lanczos;
                    image.Sharpen();
                    image.Resize((int)(k * image.Width), (int)(k * image.Height));
                    image.Crop((int)maxWidth, (int)maxHeight, Gravity.Center);
                }

                image.Quality = 95;
                image.Density = new Density(96, 96);
                if (File.Exists(destination))
                {
                    try {
                        File.Delete(destination);
                    } catch (UnauthorizedAccessException) {
                        Thread.Sleep(200);
                        File.Delete(destination);
                    }
                }

                var profile = new ExifProfile();
                profile.SetValue(ExifTag.Software, AcToolsInformation.Name);

                if (information?.ExifStyle != null)
                {
                    profile.SetValue(ExifTag.Artist, information.ExifStyle);
                }

                if (information?.Name != null)
                {
                    profile.SetValue(ExifTag.ImageDescription, information.Name);
                }

                image.AddProfile(profile);
                image.Write(destination);
            }
        }
            public void ShouldReturnFalseWhenValueIsInvalidDataType1()
            {
                var profile = new ExifProfile();

                profile.SetValue(ExifTag.Software, "Magick.NET");

                IExifValue value = profile.GetValue(ExifTag.Software);

                Assert.False(value.SetValue(10.5));
            }
Exemple #7
0
        public void SyncProfiles()
        {
            var exifProfile = new ExifProfile();

            exifProfile.SetValue(ExifTag.XResolution, new Rational(200));
            exifProfile.SetValue(ExifTag.YResolution, new Rational(300));

            using (var image = new Image <Rgba32>(1, 1))
            {
                image.Metadata.ExifProfile          = exifProfile;
                image.Metadata.HorizontalResolution = 400;
                image.Metadata.VerticalResolution   = 500;

                image.Metadata.SyncProfiles();

                Assert.Equal(400, ((Rational)image.Metadata.ExifProfile.GetValue(ExifTag.XResolution).Value).ToDouble());
                Assert.Equal(500, ((Rational)image.Metadata.ExifProfile.GetValue(ExifTag.YResolution).Value).ToDouble());
            }
        }
Exemple #8
0
        private static ExifProfile CreateExifProfile()
        {
            var profile = new ExifProfile();

            foreach (KeyValuePair <ExifTag, object> exifProfileValue in TestProfileValues)
            {
                profile.SetValue(exifProfileValue.Key, exifProfileValue.Value);
            }

            return(profile);
        }
        private async Task UploadImageAsync(string id, Image <Rgba32> image)
        {
            var fileName = $"./{id}.gif";
            var profile  = new ExifProfile();

            profile.SetValue(ExifTag.Copyright, _processingOptions.Copyright);
            image.MetaData.ExifProfile = profile;
            image.Save(fileName, _encoder);

            await _imageRepository.UploadImageAsync(id, fileName);
        }
Exemple #10
0
        public void HelperCanChangeExifDataType()
        {
            int xy = 1;

            using (var img = new Image <Alpha8>(xy, xy))
            {
                var profile = new ExifProfile();
                img.MetaData.ExifProfile = profile;
                profile.SetValue(ExifTag.PixelXDimension, (uint)xy);
                profile.SetValue(ExifTag.PixelYDimension, (uint)xy);

                Assert.Equal(ExifDataType.Long, profile.GetValue(ExifTag.PixelXDimension).DataType);
                Assert.Equal(ExifDataType.Long, profile.GetValue(ExifTag.PixelYDimension).DataType);

                TransformHelpers.UpdateDimensionalMetData(img);

                Assert.Equal(ExifDataType.Short, profile.GetValue(ExifTag.PixelXDimension).DataType);
                Assert.Equal(ExifDataType.Short, profile.GetValue(ExifTag.PixelYDimension).DataType);
            }
        }
            public void ShouldCorrectlyHandleFraction()
            {
                var profile = new ExifProfile();

                profile.SetValue(ExifTag.ShutterSpeedValue, new SignedRational(75.55));

                var value = profile.GetValue(ExifTag.ShutterSpeedValue);

                Assert.IsNotNull(value);
                Assert.AreEqual("1511/20", value.ToString());
            }
Exemple #12
0
            public void ShouldExcludeEmptyStrings()
            {
                var profile = new ExifProfile();

                profile.SetValue(ExifTag.ImageDescription, string.Empty);

                var data = profile.ToByteArray();

                var result = ExifReader.Read(data);

                Assert.Empty(result.Values);
            }
Exemple #13
0
        /// <summary>
        /// Updates the dimensional metadata of a transformed image
        /// </summary>
        /// <typeparam name="TPixel">The pixel format.</typeparam>
        /// <param name="image">The image to update</param>
        public static void UpdateDimensionalMetadata <TPixel>(Image <TPixel> image)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            ExifProfile profile = image.Metadata.ExifProfile;

            if (profile is null)
            {
                return;
            }

            // Only set the value if it already exists.
            if (profile.GetValue(ExifTag.PixelXDimension) != null)
            {
                profile.SetValue(ExifTag.PixelXDimension, image.Width);
            }

            if (profile.GetValue(ExifTag.PixelYDimension) != null)
            {
                profile.SetValue(ExifTag.PixelYDimension, image.Height);
            }
        }
        private void AutoRotate(MagickImage image)
        {
            ExifProfile profile = image.GetExifProfile();

            if (!(profile is null))
            {
                string orientation = profile.GetValue(ExifTag.Orientation)?.ToString() ?? "";
                if (!String.IsNullOrWhiteSpace(orientation))
                {
                    switch (orientation)
                    {
                    case "2":
                        image.Flop();     //x-axis
                        break;

                    case "3":
                        image.Rotate(180);
                        break;

                    case "4":
                        image.Rotate(180);
                        image.Flop();     //x-axis
                        break;

                    case "5":
                        image.Rotate(90);
                        image.Flop();     //x-axis
                        break;

                    case "6":
                        image.Rotate(90);
                        break;

                    case "7":
                        image.Rotate(270);
                        image.Flop();     //x-axis
                        break;

                    case "8":
                        image.Rotate(270);
                        break;

                    case "1":
                    case "1H":
                    default:
                        break;
                    }
                    ushort defaultOrient = 1;
                    profile.SetValue(ExifTag.Orientation, defaultOrient);
                    image.Write(image.FileName);
                }
            }
        }
Exemple #15
0
        public void Test_Fraction()
        {
            using (MemoryStream memStream = new MemoryStream())
            {
                double exposureTime = 1.0 / 1600;

                using (MagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
                {
                    ExifProfile profile = image.GetExifProfile();

                    profile.SetValue(ExifTag.ExposureTime, exposureTime);
                    image.AddProfile(profile);

                    image.Write(memStream);
                }

                memStream.Position = 0;
                using (MagickImage image = new MagickImage(memStream))
                {
                    ExifProfile profile = image.GetExifProfile();

                    Assert.IsNotNull(profile);

                    ExifValue value = profile.GetValue(ExifTag.ExposureTime);
                    Assert.IsNotNull(value);
                    Assert.AreNotEqual(exposureTime, value.Value);
                }

                memStream.Position = 0;
                using (MagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
                {
                    ExifProfile profile = image.GetExifProfile();

                    profile.SetValue(ExifTag.ExposureTime, exposureTime);
                    profile.BestPrecision = true;
                    image.AddProfile(profile);

                    image.Write(memStream);
                }

                memStream.Position = 0;
                using (MagickImage image = new MagickImage(memStream))
                {
                    ExifProfile profile = image.GetExifProfile();

                    Assert.IsNotNull(profile);

                    ExifValue value = profile.GetValue(ExifTag.ExposureTime);
                    TestValue(value, exposureTime);
                }
            }
        }
Exemple #16
0
        public void WriteFraction(TestImageWriteFormat imageFormat)
        {
            using (var memStream = new MemoryStream())
            {
                double exposureTime = 1.0 / 1600;

                ExifProfile profile = GetExifProfile();

                profile.SetValue(ExifTag.ExposureTime, new Rational(exposureTime));

                var image = new Image <Rgba32>(1, 1);
                image.Metadata.ExifProfile = profile;

                image = WriteAndRead(image, imageFormat);

                profile = image.Metadata.ExifProfile;
                Assert.NotNull(profile);

                IExifValue <Rational> value = profile.GetValue(ExifTag.ExposureTime);
                Assert.NotNull(value);
                Assert.NotEqual(exposureTime, value.Value.ToDouble());

                memStream.Position = 0;
                profile            = GetExifProfile();

                profile.SetValue(ExifTag.ExposureTime, new Rational(exposureTime, true));
                image.Metadata.ExifProfile = profile;

                image = WriteAndRead(image, imageFormat);

                profile = image.Metadata.ExifProfile;
                Assert.NotNull(profile);

                value = profile.GetValue(ExifTag.ExposureTime);
                Assert.Equal(exposureTime, value.Value.ToDouble());

                image.Dispose();
            }
        }
Exemple #17
0
            public void ShouldThrowExceptionWhenValueIsInvalidDataType1()
            {
                var profile = new ExifProfile();

                profile.SetValue(ExifTag.Software, "Magick.NET");

                var value = profile.GetValue(ExifTag.Software);

                ExceptionAssert.Throws <ArgumentException>("value", () =>
                {
                    value.Value = 15;
                });
            }
        /// <summary>
        /// Updates the dimensional metadata of a transformed image
        /// </summary>
        /// <typeparam name="TPixel">The pixel format.</typeparam>
        /// <param name="image">The image to update</param>
        public static void UpdateDimensionalMetData <TPixel>(Image <TPixel> image)
            where TPixel : struct, IPixel <TPixel>
        {
            ExifProfile profile = image.MetaData.ExifProfile;

            if (profile == null)
            {
                return;
            }

            // Removing the previously stored value allows us to set a value with our own data tag if required.
            if (profile.GetValue(ExifTag.PixelXDimension) != null)
            {
                profile.RemoveValue(ExifTag.PixelXDimension);

                if (image.Width <= ushort.MaxValue)
                {
                    profile.SetValue(ExifTag.PixelXDimension, (ushort)image.Width);
                }
                else
                {
                    profile.SetValue(ExifTag.PixelXDimension, (uint)image.Width);
                }
            }

            if (profile.GetValue(ExifTag.PixelYDimension) != null)
            {
                profile.RemoveValue(ExifTag.PixelYDimension);

                if (image.Height <= ushort.MaxValue)
                {
                    profile.SetValue(ExifTag.PixelYDimension, (ushort)image.Height);
                }
                else
                {
                    profile.SetValue(ExifTag.PixelYDimension, (uint)image.Height);
                }
            }
        }
Exemple #19
0
            public void ShouldThrowExceptionWhenValueIsInvalidDataType2()
            {
                var profile = new ExifProfile();

                profile.SetValue(ExifTag.ShutterSpeedValue, new SignedRational(75.55));

                var value = profile.GetValue(ExifTag.ShutterSpeedValue);

                ExceptionAssert.Throws <ArgumentException>("value", () =>
                {
                    value.Value = 75;
                });
            }
            public void ShouldReturnFalseWhenValueIsInvalidDataType3()
            {
                var profile = new ExifProfile();

                profile.SetValue(ExifTag.XResolution, new Rational(150.0));

                IExifValue value = profile.GetValue(ExifTag.XResolution);

                Assert.NotNull(value);
                Assert.Equal("150", value.ToString());

                Assert.False(value.SetValue("Magick.NET"));
            }
Exemple #21
0
        public void EmptyWriter()
        {
            var profile = new ExifProfile()
            {
                Parts = ExifParts.GpsTags
            };

            profile.SetValue(ExifTag.Copyright, "Copyright text");

            byte[] bytes = profile.ToByteArray();

            Assert.NotNull(bytes);
            Assert.Empty(bytes);
        }
Exemple #22
0
            public void ShouldExcludeNullValues()
            {
                var profile = new ExifProfile();

                profile.SetValue(ExifTag.ImageDescription, null);

                var data = profile.ToByteArray();

                var reader = new ExifReader();

                reader.Read(data);

                EnumerableAssert.IsEmpty(reader.Values);
            }
Exemple #23
0
            public void ShouldExcludeNullValues()
            {
                var profile = new ExifProfile();

                profile.SetValue(ExifTag.ImageDescription, null);

                var data = profile.ToByteArray();

                var reader = new ExifReader();

                reader.Read(data);

                Assert.AreEqual(0, reader.Values.Count);
            }
Exemple #24
0
        /// <inheritdoc/>
        protected override void AfterImageApply(Image <TPixel> source, Rectangle sourceRectangle)
        {
            ExifProfile profile = source.MetaData.ExifProfile;

            if (profile == null)
            {
                return;
            }

            if (MathF.Abs(this.Angle) < Constants.Epsilon)
            {
                // No need to do anything so return.
                return;
            }

            profile.RemoveValue(ExifTag.Orientation);

            if (this.Expand && profile.GetValue(ExifTag.PixelXDimension) != null)
            {
                profile.SetValue(ExifTag.PixelXDimension, source.Width);
                profile.SetValue(ExifTag.PixelYDimension, source.Height);
            }
        }
            public void ShouldThrowExceptionWhenValueIsInvalidDataType2()
            {
                var profile = new ExifProfile();

                profile.SetValue(ExifTag.ShutterSpeedValue, new SignedRational(75.55));

                var value = profile.GetValue(ExifTag.ShutterSpeedValue);

                var exception = ExceptionAssert.Throws <InvalidOperationException>(() =>
                {
                    value.Value = 75;
                });

                Assert.AreEqual("The type of the value should be SignedRational.", exception.Message);
            }
Exemple #26
0
            public void ShouldThrowExceptionWhenValueIsInvalidDataType3()
            {
                var profile = new ExifProfile();

                profile.SetValue(ExifTag.XResolution, new Rational(150.0));

                var value = profile.GetValue(ExifTag.XResolution);

                TestRationalValue(value, "150");

                ExceptionAssert.Throws <ArgumentException>("value", () =>
                {
                    value.Value = "Magick.NET";
                });
            }
        public void TestExifTag()
        {
            ExifProfile exifProfile = new ExifProfile();

            exifProfile.SetValue(ExifTag.ResolutionUnit, (ushort)1);
            ExifValue value = exifProfile.GetValue(ExifTag.ResolutionUnit);
            Assert.Equal("None", value.ToString());

            exifProfile.SetValue(ExifTag.ResolutionUnit, (ushort)2);
            value = exifProfile.GetValue(ExifTag.ResolutionUnit);
            Assert.Equal("Inches", value.ToString());

            exifProfile.SetValue(ExifTag.ResolutionUnit, (ushort)3);
            value = exifProfile.GetValue(ExifTag.ResolutionUnit);
            Assert.Equal("Centimeter", value.ToString());

            exifProfile.SetValue(ExifTag.ResolutionUnit, (ushort)4);
            value = exifProfile.GetValue(ExifTag.ResolutionUnit);
            Assert.Equal("4", value.ToString());

            exifProfile.SetValue(ExifTag.ImageWidth, 123);
            value = exifProfile.GetValue(ExifTag.ImageWidth);
            Assert.Equal("123", value.ToString());
        }
Exemple #28
0
            public void ShouldCorrectlyHandleArray()
            {
                Rational[] latitude = new Rational[] { new Rational(12.3), new Rational(4.56), new Rational(789.0) };

                var profile = new ExifProfile();

                profile.SetValue(ExifTag.GPSLatitude, latitude);

                var value = profile.GetValue(ExifTag.GPSLatitude);

                Assert.NotNull(value);
                Rational[] values = (Rational[])value.GetValue();
                Assert.NotNull(values);
                Assert.Equal(latitude, values);
            }
Exemple #29
0
        public void ConstructorCopy()
        {
            Assert.Throws <ArgumentNullException>(() => { new ExifProfile((ExifProfile)null); });

            ExifProfile profile = GetExifProfile();

            ExifProfile clone = new ExifProfile(profile);

            TestProfile(clone);

            profile.SetValue(ExifTag.ColorSpace, (ushort)2);

            clone = new ExifProfile(profile);
            TestProfile(clone);
        }
Exemple #30
0
        public void ConstructorCopy()
        {
            Assert.Throws <NullReferenceException>(() => ((ExifProfile)null).DeepClone());

            ExifProfile profile = GetExifProfile();

            ExifProfile clone = profile.DeepClone();

            TestProfile(clone);

            profile.SetValue(ExifTag.ColorSpace, (ushort)2);

            clone = profile.DeepClone();
            TestProfile(clone);
        }