コード例 #1
0
        public override FileResult GetItemImage(Product product, int imageIndex, Size size)
        {
            // load directly from s3
            var name = GetImageName(product, imageIndex, size);

            if (Store.Contains(name))
            {
                return(GetFileResult(name));
            }

            // resize and add to s3
            var original = (FileContentResult)GetItemImage(product, imageIndex);
            var output   = new MemoryStream();

            using (var stream = new MemoryStream(original.FileContents))
            {
                Log.DebugFormat("Resizing image for '{0}' to {1}x{2}px.", product.Name, size.Width, size.Height);
                Resizer.ResizeImage(
                    Image.FromStream(stream),
                    new System.Drawing.Size(size.Width, size.Height),
                    output,
                    ImageFormat.Jpeg);
                var buf = output.ToArray();
                Store.Put(name, buf, "image/jpeg");
                return(GetFileResult(buf));
            }
        }
コード例 #2
0
        public override FileResult GetItemImage(Product product, int imageIndex, Size size)
        {
            if (null == size)
            {
                return(GetItemImage(product, imageIndex));
            }
            var file = GetImageName(product, imageIndex, size);

            if (!File.Exists(file))
            {
                // load the original
                var original = (FileStreamResult)GetItemImage(product, imageIndex);
                using (var stream = original.FileStream)
                {
                    var fi = new FileInfo(file);
                    if (!fi.Directory.Exists)
                    {
                        fi.Directory.Create();
                    }
                    using (var output = File.Create(file))
                    {
                        Resizer.ResizeImage(
                            Image.FromStream(stream),
                            new System.Drawing.Size(size.Width, size.Height),
                            output,
                            ImageFormat.Jpeg);
                    }
                }
            }
            return(GetFileResult(file));
        }
コード例 #3
0
        public override FileResult GetItemImage(Product product, int imageIndex, Size size)
        {
            // load directly from s3
            var name = GetImageName(product, imageIndex, size);
            if (Store.Contains(name))
            {
                return GetFileResult(name);
            }

            // resize and add to s3
            var original = (FileContentResult)GetItemImage(product, imageIndex);
            var output = new MemoryStream();
            using (var stream = new MemoryStream(original.FileContents))
            {
                Log.DebugFormat("Resizing image for '{0}' to {1}x{2}px.", product.Name, size.Width, size.Height);
                Resizer.ResizeImage(
                    Image.FromStream(stream),
                    new System.Drawing.Size(size.Width, size.Height),
                    output,
                    ImageFormat.Jpeg);
                var buf = output.ToArray();
                Store.Put(name, buf, "image/jpeg"); 
                return GetFileResult(buf);
            }
        }
コード例 #4
0
        protected virtual string GetImageName(Product p, int i, Size size)
        {
            string path = Configuration.ImageFolder;

            if (null != size)
            {
                path = Path.Combine(path, String.Format("{0}x{1}", size.Width, size.Height));
            }
            if (i > 0)
            {
                path = Path.Combine(path, i.ToString());
            }
            path = Path.Combine(path, p.ProductId + ".jpeg");
            return(path);
        }
コード例 #5
0
        public override string GetExternalImageUrl(string productId, int imageIndex, Size size)
        {
            var name = GetImageName(productId, imageIndex, size);

            return(Store.Contains(name) ? String.Format(_imageUrlFormat, Store.Name, name) : null);
        }
コード例 #6
0
 protected static string GetImageName(string productId, int i, Size size)
 {
     return((null == size)
         ? String.Format("{0}.jpeg", productId)
         : String.Format("{0}-{1}-{2}x{3}.jpeg", productId, i, size.Width, size.Height));
 }
コード例 #7
0
 protected static string GetImageName(Product p, int i, Size size)
 {
     return(GetImageName(p.ProductId, i, size));
 }
コード例 #8
0
 public abstract string GetExternalImageUrl(string productId, int imageIndex, Size size);
コード例 #9
0
 public abstract FileResult GetItemImage(Product product, int imageIndex, Size size);
コード例 #10
0
 public override string GetExternalImageUrl(string productId, int imageIndex, Size size)
 {
     return(null);
 }
コード例 #11
0
 public override string GetExternalImageUrl(string productId, int imageIndex, Size size)
 {
     var name = GetImageName(productId, imageIndex, size);
     return Store.Contains(name) ? String.Format(_imageUrlFormat, Store.Name, name) : null;
 }
コード例 #12
0
 protected static string GetImageName(string productId, int i, Size size)
 {
     return (null == size)
         ? String.Format("{0}.jpeg", productId)
         : String.Format("{0}-{1}-{2}x{3}.jpeg", productId, i, size.Width, size.Height);
 }
コード例 #13
0
 protected static string GetImageName(Product p, int i, Size size)
 {
     return GetImageName(p.ProductId, i, size);
 }