Example #1
0
        public void BaseCreateThumbnail(ImageCreateThumbnail method)
        {
            var mediaType = new MediaTypes(this.Strategy.Session).Png;

            byte[] content;

            // Stream should be left open for Save to work
            using (Stream stream = new MemoryStream(this.Original.Content))
            {
                var thumbnail = new Bitmap(stream);

                thumbnail = thumbnail.Rotate();
                thumbnail = thumbnail.MaxHeight(method.MaxHeight ?? 150);

                content = thumbnail.Save(ImageFormat.Png);
            }

            if (!this.ExistThumbnail || !content.SequenceEqual(this.Thumbnail.Content))
            {
                if (this.ExistThumbnail)
                {
                    this.Thumbnail.Delete();
                }

                this.Thumbnail = new MediaBuilder(this.Strategy.Session).WithContent(content).WithMediaType(mediaType).Build();
            }
        }
Example #2
0
        public void BaseCreateResponsive(ImageCreateResponsive method)
        {
            var mediaType = new MediaTypes(this.Strategy.Session).Jpeg;

            byte[] content;

            // Stream should be left open for Save to work
            using (Stream stream = new MemoryStream(this.Original.Content))
            {
                var responsive = new Bitmap(stream);

                responsive = responsive.Rotate();
                responsive = responsive.MaxHeight(method.MaxHeight ?? 600);

                var encoder = ImageCodecInfo.GetImageEncoders().FirstOrDefault(e => e.MimeType == mediaType.Name);
                var encoderParams = new EncoderParameters(1);
                var qualityParam = Encoder.Quality;
                encoderParams.Param[0] = new EncoderParameter(qualityParam, 72L);

                content = responsive.Save(encoder, encoderParams);
            }

            if (!this.ExistResponsive || !content.SequenceEqual(this.Responsive.Content))
            {
                if (this.ExistResponsive)
                {
                    this.Responsive.Delete();
                }

                this.Responsive = new MediaBuilder(this.Strategy.Session).WithContent(content).WithMediaType(mediaType).Build();
            }
        }
Example #3
0
        public void Hash()
        {
            var binary = new byte[] { 0, 1, 2, 3 };
            var octetStream = new MediaTypes(this.DatabaseSession).OctetStream;

            this.DatabaseSession.Commit();

            var media = new MediaBuilder(this.DatabaseSession).WithContent(binary).WithMediaType(octetStream).Build();

            this.DatabaseSession.Derive(true);

            Assert.IsTrue(media.ExistMediaContent);
            Assert.IsTrue(media.MediaContent.ExistHash);
        }
Example #4
0
        public void HashedContent()
        {
            var binary = new byte[] { 0, 1, 2, 3 };
            var sameBinary = new byte[] { 0, 1, 2, 3 };
            var differentBinary = new byte[] { 1, 0, 2, 3 };

            var octetStream = new MediaTypes(this.DatabaseSession).OctetStream;
            var media1 = new MediaBuilder(this.DatabaseSession).WithContent(binary).WithMediaType(octetStream).Build();
            var media2 = new MediaBuilder(this.DatabaseSession).WithContent(sameBinary).WithMediaType(octetStream).Build();
            var media3 = new MediaBuilder(this.DatabaseSession).WithContent(differentBinary).WithMediaType(octetStream).Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(media1.MediaContent.Hash, media2.MediaContent.Hash);
            Assert.AreNotEqual(media1.MediaContent.Hash, media3.MediaContent.Hash);
        }