public static void GeneratePreview(string path, string outputPath, ref ImageInfo imageInfo) { ThumbnailGenerator _generator = new ThumbnailGenerator(null, true, maxSize, maxSize, maxWidthPreview, maxHeightPreview); _generator.DoPreviewImage(path, outputPath, ref imageInfo); }
public static void GeneratePreview(Stream stream, string outputPath, ref ImageInfo imageInfo, IDataStore store) { ThumbnailGenerator _generator = new ThumbnailGenerator(null, true, maxSize, maxSize, maxWidthPreview, maxHeightPreview); _generator.store = store; _generator.DoPreviewImage(stream, outputPath, ref imageInfo); }
public static void GenerateThumbnail(Stream stream, string outputPath, ref ImageInfo imageInfo, int maxWidth, int maxHeight) { ThumbnailGenerator _generator = new ThumbnailGenerator(null, true, maxWidth, maxHeight, maxWidthPreview, maxHeightPreview); _generator.DoThumbnail(stream, outputPath, ref imageInfo); }
public static void GenerateThumbnail(string path, string outputPath, ref ImageInfo imageInfo, int maxWidth, int maxHeight, IDataStore store) { ThumbnailGenerator _generator = new ThumbnailGenerator(null, true, maxWidth, maxHeight, maxWidthPreview, maxHeightPreview); _generator.store = store; _generator.DoThumbnail(path, outputPath, ref imageInfo); }
public void DoPreviewImage(Stream image, string outputPath, ref ImageInfo imageInfo) { using (Image img = Image.FromStream(image)) { DoPreviewImage(img, outputPath, ref imageInfo); } }
public void DoPreviewImage(Image image, string outputPath, ref ImageInfo imageInfo) { int realWidth = image.Width; int realHeight = image.Height; int heightPreview = realHeight; int widthPreview = realWidth; EncoderParameters ep = new EncoderParameters(1); ImageCodecInfo icJPG = getCodecInfo("image/jpeg"); ep.Param[0] = new EncoderParameter(Encoder.Quality, (long)90); if (realWidth <= _widthPreview && realHeight <= _heightPreview) { imageInfo.PreviewWidth = widthPreview; imageInfo.PreviewHeight = heightPreview; if (store == null) image.Save(outputPath); else { MemoryStream ms = new MemoryStream(); image.Save(ms, icJPG, ep); ms.Seek(0, SeekOrigin.Begin); store.Save(outputPath, ms); ms.Dispose(); } return; } else if ((double)realHeight / (double)_heightPreview > (double)realWidth / (double)_widthPreview) { if (heightPreview > _heightPreview) { widthPreview = (int)(realWidth * _heightPreview * 1.0 / realHeight + 0.5); heightPreview = _heightPreview; } } else { if (widthPreview > _widthPreview) { heightPreview = (int)(realHeight * _widthPreview * 1.0 / realWidth + 0.5); widthPreview = _widthPreview; } } imageInfo.PreviewWidth = widthPreview; imageInfo.PreviewHeight = heightPreview; Bitmap preview = new Bitmap(widthPreview, heightPreview); using (Graphics graphic = Graphics.FromImage(preview)) { graphic.InterpolationMode = InterpolationMode.HighQualityBicubic; graphic.PixelOffsetMode = PixelOffsetMode.HighQuality; graphic.DrawImage(image, 0, 0, widthPreview, heightPreview); } if (store == null) preview.Save(outputPath, icJPG, ep); else { MemoryStream ms = new MemoryStream(); preview.Save(ms, icJPG, ep); ms.Seek(0, SeekOrigin.Begin); store.Save(outputPath, ms); ms.Dispose(); } preview.Dispose(); }
public void DoThumbnail(Image image, string outputPath, ref ImageInfo imageInfo) { int realWidth = image.Width; int realHeight = image.Height; imageInfo.OriginalWidth = realWidth; imageInfo.OriginalHeight = realHeight; EncoderParameters ep = new EncoderParameters(1); ep.Param[0] = new EncoderParameter(Encoder.Quality, (long)90); ImageCodecInfo icJPG = getCodecInfo("image/jpeg"); if (!String.IsNullOrEmpty(imageInfo.Name) && imageInfo.Name.Contains(".")) { int indexDot = imageInfo.Name.ToLower().LastIndexOf("."); if (imageInfo.Name.ToLower().IndexOf("png", indexDot) > indexDot) icJPG = getCodecInfo("image/png"); else if (imageInfo.Name.ToLower().IndexOf("gif", indexDot) > indexDot) icJPG = getCodecInfo("image/png"); } Bitmap thumbnail; if (realWidth < _width && realHeight < _heigth) { imageInfo.ThumbnailWidth = realWidth; imageInfo.ThumbnailHeight = realHeight; if (store == null) image.Save(outputPath); else { MemoryStream ms = new MemoryStream(); image.Save(ms, icJPG, ep); ms.Seek(0, SeekOrigin.Begin); store.Save(outputPath, ms); ms.Dispose(); } return; } else { thumbnail = new Bitmap(_width < realWidth ? _width : realWidth, _heigth < realHeight ? _heigth : realHeight); int maxSide = realWidth > realHeight ? realWidth : realHeight; int minSide = realWidth < realHeight ? realWidth : realHeight; bool alignWidth = true; if (_crop) alignWidth = (minSide == realWidth); else alignWidth = (maxSide == realWidth); double scaleFactor = (alignWidth) ? (realWidth / (1.0 * _width)) : (realHeight / (1.0 * _heigth)); if (scaleFactor < 1) scaleFactor = 1; int locationX, locationY; int finalWidth, finalHeigth; finalWidth = (int)(realWidth / scaleFactor); finalHeigth = (int)(realHeight / scaleFactor); locationY = (int)(((_heigth < realHeight ? _heigth : realHeight) / 2.0) - (finalHeigth / 2.0)); locationX = (int)(((_width < realWidth ? _width : realWidth) / 2.0) - (finalWidth / 2.0)); Rectangle rect = new Rectangle(locationX, locationY, finalWidth, finalHeigth); imageInfo.ThumbnailWidth = thumbnail.Width; imageInfo.ThumbnailHeight = thumbnail.Height; using (Graphics graphic = Graphics.FromImage(thumbnail)) { graphic.InterpolationMode = InterpolationMode.HighQualityBicubic; graphic.PixelOffsetMode = PixelOffsetMode.HighQuality; graphic.DrawImage(image, rect); } } if (store == null) thumbnail.Save(outputPath, icJPG, ep); else { MemoryStream ms = new MemoryStream(); thumbnail.Save(ms, icJPG, ep); ms.Seek(0, SeekOrigin.Begin); store.Save(outputPath, ms); ms.Dispose(); } thumbnail.Dispose(); }
public void DoPreviewImage(string path, string outputPath, ref ImageInfo imageInfo) { using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)) { DoPreviewImage(fs, outputPath, ref imageInfo); } }
public void DoThumbnail(Stream image, string outputPath, ref ImageInfo imageInfo) { using (Image img = Image.FromStream(image)) { DoThumbnail(img, outputPath, ref imageInfo); } }
internal void GenerateImageThumb(File file) { if (file == null || FileUtility.GetFileTypeByFileName(file.Title) != FileType.Image) return; try { using (var filedao = FilesIntegration.GetFileDao()) { using (var stream = filedao.GetFileStream(file)) { var ii = new ImageInfo(); ImageHelper.GenerateThumbnail(stream, GetThumbPath(file.ID), ref ii, 128, 96, projectsStore); } } } catch (Exception ex) { LogManager.GetLogger("ASC.Web.Projects").Error(ex); } }
public override FileUploadResult ProcessUpload(HttpContext context) { if (!ASC.Core.SecurityContext.AuthenticateMe(CookiesManager.GetCookies(CookiesType.AuthKey))) { return new FileUploadResult { Success = false, Message = "Permission denied" }; } var result = ""; try { if (ProgressFileUploader.HasFilesToUpload(context)) { var postedFile = new ProgressFileUploader.FileToUpload(context); var fileName = postedFile.FileName; var inputStream = postedFile.InputStream; var store = Data.Storage.StorageFactory.GetStorage(TenantProvider.CurrentTenantID.ToString(), "photo"); var storage = StorageFactory.GetStorage(); var uid = context.Request["uid"]; var eventID = context.Request["eventID"]; var albums = storage.GetAlbums(Convert.ToInt64(eventID), uid); var currentAlbum = 0 < albums.Count ? albums[0] : null; if (currentAlbum == null) { var Event = storage.GetEvent(Convert.ToInt64(eventID)); currentAlbum = new Album { Event = Event, UserID = uid }; storage.SaveAlbum(currentAlbum); } if (context.Session["photo_albumid"] != null) { context.Session["photo_albumid"] = currentAlbum.Id; } var fileNamePath = PhotoConst.ImagesPath + uid + "/" + currentAlbum.Id + "/"; var currentImageInfo = new ImageInfo(); var listFiles = store.ListFilesRelative("", fileNamePath, "*.*", false); context.Session["photo_listFiles"] = listFiles; var fileExtension = FileUtility.GetFileExtension(fileName); var fileNameWithOutExtension = GetFileName(fileName); var addSuffix = string.Empty; //if file already exists var i = 1; while (CheckFile(listFiles, fileNameWithOutExtension + addSuffix + PhotoConst.THUMB_SUFFIX + fileExtension)) { addSuffix = "(" + i.ToString() + ")"; i++; } var fileNameThumb = fileNamePath + fileNameWithOutExtension + addSuffix + PhotoConst.THUMB_SUFFIX + "." + PhotoConst.jpeg_extension; var fileNamePreview = fileNamePath + fileNameWithOutExtension + addSuffix + PhotoConst.PREVIEW_SUFFIX + "." + PhotoConst.jpeg_extension; currentImageInfo.Name = fileNameWithOutExtension; currentImageInfo.PreviewPath = fileNamePreview; currentImageInfo.ThumbnailPath = fileNameThumb; var fs = inputStream; try { var reader = new EXIFReader(fs); currentImageInfo.ActionDate = (string) reader[PropertyTagId.DateTime]; } catch { } ImageHelper.GenerateThumbnail(fs, fileNameThumb, ref currentImageInfo, store); ImageHelper.GeneratePreview(fs, fileNamePreview, ref currentImageInfo, store); fs.Dispose(); var image = new AlbumItem(currentAlbum) { Name = currentImageInfo.Name, Timestamp = ASC.Core.Tenants.TenantUtil.DateTimeNow(), UserID = uid, Location = currentImageInfo.Name, PreviewSize = new Size(currentImageInfo.PreviewWidth, currentImageInfo.PreviewHeight), ThumbnailSize = new Size(currentImageInfo.ThumbnailWidth, currentImageInfo.ThumbnailHeight) }; storage.SaveAlbumItem(image); currentAlbum.FaceItem = image; storage.SaveAlbum(currentAlbum); var response = image.Id.ToString(); var byteArray = System.Text.Encoding.UTF8.GetBytes(response); result = Convert.ToBase64String(byteArray); } } catch (Exception ex) { return new FileUploadResult { Success = false, Message = ex.Message, }; } return new FileUploadResult { Success = true, Data = "", Message = result }; }
private List<string> CreateImagesInfoBySimple() { var info = new List<string>(); var store = Data.Storage.StorageFactory.GetStorage(TenantProvider.CurrentTenantID.ToString(), "photo"); var storage = StorageFactory.GetStorage(); var uid = SecurityContext.CurrentAccount.ID.ToString(); var eventID = Request["events_selector"]; var albums = storage.GetAlbums(Convert.ToInt64(eventID), uid); var currentAlbum = 0 < albums.Count ? albums[0] : null; if (currentAlbum == null) { var Event = storage.GetEvent(Convert.ToInt64(eventID)); currentAlbum = new Album {Event = Event, UserID = uid}; storage.SaveAlbum(currentAlbum); } var fileNamePath = PhotoConst.ImagesPath + uid + "/" + currentAlbum.Id + "/"; var listFiles = store.ListFilesRelative("", fileNamePath, "*.*", false); for (var j = 0; j < Request.Files.Count; j++) { var file = Request.Files[j]; if (file.ContentLength > SetupInfo.MaxUploadSize) continue; if (string.IsNullOrEmpty(file.FileName)) continue; var currentImageInfo = new ImageInfo(); var fileExtension = FileUtility.GetFileExtension(file.FileName); var fileNameWithOutExtension = FileUtility.GetFileName(file.FileName); var addSuffix = string.Empty; var i = 1; while (CheckFile(listFiles, fileNameWithOutExtension + addSuffix + PhotoConst.THUMB_SUFFIX + fileExtension)) { addSuffix = "(" + i.ToString() + ")"; i++; } var fileNameThumb = fileNamePath + fileNameWithOutExtension + addSuffix + PhotoConst.THUMB_SUFFIX + "." + PhotoConst.jpeg_extension; var fileNamePreview = fileNamePath + fileNameWithOutExtension + addSuffix + PhotoConst.PREVIEW_SUFFIX + "." + PhotoConst.jpeg_extension; currentImageInfo.Name = fileNameWithOutExtension; currentImageInfo.PreviewPath = fileNamePreview; currentImageInfo.ThumbnailPath = fileNameThumb; var fs = file.InputStream; try { var reader = new EXIFReader(fs); currentImageInfo.ActionDate = (string) reader[PropertyTagId.DateTime]; } catch { } ImageHelper.GenerateThumbnail(fs, fileNameThumb, ref currentImageInfo, store); ImageHelper.GeneratePreview(fs, fileNamePreview, ref currentImageInfo, store); fs.Dispose(); var image = new AlbumItem(currentAlbum) { Name = currentImageInfo.Name, Timestamp = ASC.Core.Tenants.TenantUtil.DateTimeNow(), UserID = uid, Location = currentImageInfo.Name, PreviewSize = new Size(currentImageInfo.PreviewWidth, currentImageInfo.PreviewHeight), ThumbnailSize = new Size(currentImageInfo.ThumbnailWidth, currentImageInfo.ThumbnailHeight) }; storage.SaveAlbumItem(image); currentAlbum.FaceItem = image; storage.SaveAlbum(currentAlbum); info.Add(image.Id.ToString()); } return info; }
protected void Page_Load(object sender, EventArgs e) { try { // Get the data HttpPostedFile jpeg_image_upload = Request.Files["Filedata"]; IDataStore store = StorageFactory.GetStorage(TenantProvider.CurrentTenantID.ToString(), "photo"); var storage = ASC.PhotoManager.Model.StorageFactory.GetStorage(); string uid = Request["uid"]; string eventID = Request["eventID"]; bool clearSession = false; Album currentAlbum = null; var albums = storage.GetAlbums(Convert.ToInt64(eventID), uid); clearSession = true; currentAlbum = 0 < albums.Count ? albums[0] : null; if (currentAlbum == null) { Event Event = storage.GetEvent(Convert.ToInt64(eventID)); currentAlbum = new Album(); currentAlbum.Event = Event; currentAlbum.UserID = uid; storage.SaveAlbum(currentAlbum); } if (Session["photo_albumid"] != null) { if (currentAlbum.Id != (long)Session["photo_albumid"]) clearSession = true; Session["photo_albumid"] = currentAlbum.Id; } else clearSession = true; string fileNamePath = Resources.PhotoManagerResource.ImagesPath + uid + "/" + currentAlbum.Id + "/"; ImageInfo currentImageInfo = new ImageInfo(); string[] listFiles; if (Session["photo_listFiles"] != null && !clearSession) listFiles = (string[])Session["photo_listFiles"]; else { listFiles = store.ListFilesRelative("", fileNamePath, "*.*", false); Session["photo_listFiles"] = listFiles; } string fileExtension = GetFileExtension(jpeg_image_upload.FileName); string fileNameWithOutExtension = GetFileName(jpeg_image_upload.FileName); string addSuffix = string.Empty; //if file already exists int i = 1; while (CheckFile(listFiles, fileNameWithOutExtension + addSuffix + Constants.THUMB_SUFFIX + fileExtension)) { addSuffix = "(" + i.ToString() + ")"; i++; } string fileNameThumb = fileNamePath + fileNameWithOutExtension + addSuffix + Constants.THUMB_SUFFIX + "." + Constants.jpeg_extension; string fileNamePreview = fileNamePath + fileNameWithOutExtension + addSuffix + Constants.PREVIEW_SUFFIX + "." + Constants.jpeg_extension; currentImageInfo.Name = fileNameWithOutExtension; currentImageInfo.PreviewPath = fileNamePreview; currentImageInfo.ThumbnailPath = fileNameThumb; Stream fs = jpeg_image_upload.InputStream; try { EXIFReader reader = new EXIFReader(fs); currentImageInfo.ActionDate = (string)reader[PropertyTagId.DateTime]; } catch { } ImageHelper.GenerateThumbnail(fs, fileNameThumb, ref currentImageInfo, store); ImageHelper.GeneratePreview(fs, fileNamePreview, ref currentImageInfo, store); fs.Dispose(); AlbumItem image = new AlbumItem(currentAlbum); image.Name = currentImageInfo.Name; image.Timestamp = ASC.Core.Tenants.TenantUtil.DateTimeNow(); image.UserID = uid; image.Location = currentImageInfo.Name; image.PreviewSize = new Size(currentImageInfo.PreviewWidth, currentImageInfo.PreviewHeight); image.ThumbnailSize = new Size(currentImageInfo.ThumbnailWidth, currentImageInfo.ThumbnailHeight); storage.SaveAlbumItem(image); currentAlbum.FaceItem = image; storage.SaveAlbum(currentAlbum); string response = image.Id.ToString(); byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(response); string encodingResponse = Convert.ToBase64String(byteArray); Response.StatusCode = 200; Response.Write(encodingResponse); } catch { // If any kind of error occurs return a 500 Internal Server error Response.StatusCode = 500; Response.Write("An error occured"); Response.End(); } finally { Response.End(); } }