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)); } }
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)); }
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); } }
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); }
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); }
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)); }
protected static string GetImageName(Product p, int i, Size size) { return(GetImageName(p.ProductId, i, size)); }
public abstract string GetExternalImageUrl(string productId, int imageIndex, Size size);
public abstract FileResult GetItemImage(Product product, int imageIndex, Size size);
public override string GetExternalImageUrl(string productId, int imageIndex, Size size) { return(null); }
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; }
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); }
protected static string GetImageName(Product p, int i, Size size) { return GetImageName(p.ProductId, i, size); }