public void MimeType()
        {
            var expected = Guid.NewGuid().ToString();
            var data = new ImageData()
            {
                MimeType = expected
            };

            Assert.AreEqual(expected, data.MimeType);
        }
        public void Raw()
        {
            var random = new Random();
            var expected = new byte[32];
            random.NextBytes(expected);

            var data = new ImageData()
            {
                Raw = expected
            };

            Assert.AreEqual(expected, data.Raw);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Resize Image
        /// </summary>
        /// <param name="file">File</param>
        /// <param name="width">Width</param>
        /// <param name="height">Height</param>
        /// <param name="format">Format</param>
        /// <param name="quality">Quality</param>
        /// <param name="cache">Cache</param>
        /// <returns>Image Data</returns>
        public async Task<ImageData> Resize(string file, ushort width, ushort height = 0, string format = Naming.DefaultExtension, byte quality = Imaging.DefaultImageQuality, bool cache = true)
        {
            var wasCached = false;
            var imgFormat = this.imaging.Get(format, quality);

            var data = new ImageData()
            {
                MimeType = imgFormat.MimeType,
            };

            var identifier = this.naming.FromFileName(file);
            var versionName = this.naming.DynamicVersion(imgFormat.DefaultExtension, quality, width, height);
            var cachedFileName = this.naming.FileName(identifier, versionName, imgFormat.DefaultExtension);

            var streamer = this.Streamer;

            if (cache)
            {
                data.Raw = await streamer.Bytes(cachedFileName);
                wasCached = null != data.Raw;
            }

            if (!wasCached)
            {
                var version = new ImageVersion
                {
                    Height = height,
                    Width = width,
                    Format = imgFormat,
                };

                var toResize = await streamer.Bytes(file);
                data.Raw = this.imaging.Resize(toResize, version);
            }

            if (cache && !wasCached)
            {
                await this.Save(cachedFileName, data.Raw, versionName, imgFormat.MimeType, identifier, false, null, quality);
            }

            return data;
        }