public FileContentResult GetPhoto(int id) { var item = _gRepo.GetImage(id); if (item != null) { return(File(item.ImageData, item.ImageMimeType)); } else { return(null); } }
public void GetPhotoGalleryImage(int id, int width = 0, int height = 0, bool isGallery = true) { if (!isGallery) { var item = _gRep.GetImage(id); if (item.ImageData != null && width > 0) { //var halfHeight = height; //var halfWidth = width; //if (width > 1280) //{ // halfHeight = new WebImage(item.ImageData).Height / 2; // halfWidth = new WebImage(item.ImageData).Width / 2; //} //var fileExt = new WebImage(item.ImageData).ImageFormat; new WebImage(item.ImageData) .Resize(width, height, true, true) // Resizing the image to 100x100 px on the fly... .Crop(1, 1) // Cropping it to remove 1px border at top and left sides (bug in WebImage) .Write(); } else if (width == 0 && height == 0 && item.ImageData != null) { new WebImage(item.ImageData) .Resize(800, 600) // Resizing the image to 100x100 px on the fly... .Crop(1, 1) // Cropping it to remove 1px border at top and left sides (bug in WebImage) .Write(); } else { //var file = new FileInfo(Server.MapPath("/Content/main-images/photouser1.jpg")); new WebImage(Server.MapPath("/Content/main-images/photouser1.jpg")).Resize(width, height, false, true).Crop(1, 1).Write(); } } else { var item = _gRep.GetGallery(id); if (item.GalleryData != null) { if (width == 0) { new WebImage(item.GalleryData) .Crop(1, 1).Write(); } else { var halfHeight = height; var halfWidth = width; //if (width > 1600) //{ // halfHeight = new WebImage(item.GalleryData).Height / 2; // halfWidth = new WebImage(item.GalleryData).Width / 2; //} var fileExt = new WebImage(item.GalleryData).ImageFormat; var img = new WebImage(item.GalleryData) .Resize(halfWidth, halfHeight, false, false) // Resizing the image to 100x100 px on the fly... .Crop(1, 1) // Cropping it to remove 1px border at top and left sides (bug in WebImage) .Write(); } } else { //var file = new FileInfo(Server.MapPath("/Content/main-images/photouser1.jpg")); new WebImage(item.GalleryData) .Crop(1, 1).Write(); } } }