private static String ExecResizeImage(byte[] imageData, Size fotoSize, IDataStore dataStore, String photoPath) { var data = imageData; using (var stream = new MemoryStream(data)) using (var img = new Bitmap(stream)) { var imgFormat = img.RawFormat; if (fotoSize != img.Size) { using (var img2 = CommonPhotoManager.DoThumbnail(img, fotoSize, false, false, false)) { data = CommonPhotoManager.SaveToBytes(img2, Global.GetImgFormatName(imgFormat)); } } else { data = Global.SaveToBytes(img); } using (var fileStream = new MemoryStream(data)) { var photoUri = dataStore.Save(photoPath, fileStream).ToString(); photoUri = String.Format("{0}?cd={1}", photoUri, DateTime.UtcNow.Ticks); return(photoUri); } } }
private static void ResizeLogo(WhiteLabelLogoTypeEnum type, String fileName, byte[] data, long maxFileSize, Size size, IDataStore store) { //Resize synchronously if (data == null || data.Length <= 0) { throw new UnknownImageFormatException(); } if (maxFileSize != -1 && data.Length > maxFileSize) { throw new ImageWeightLimitException(); } try { using (var stream = new MemoryStream(data)) using (var img = Image.FromStream(stream)) { var imgFormat = img.RawFormat; if (size != img.Size) { using (var img2 = CommonPhotoManager.DoThumbnail(img, size, false, true, false)) { data = CommonPhotoManager.SaveToBytes(img2); } } else { data = CommonPhotoManager.SaveToBytes(img); } //fileExt = CommonPhotoManager.GetImgFormatName(imgFormat); using (var stream2 = new MemoryStream(data)) { store.Save(fileName, stream2); //NOTE: Update cache here //var filePath = Path.GetFileName(photoUrl); //AddToCache(item.UserId, item.Size, fileNPath, true); } } } catch (ArgumentException error) { throw new UnknownImageFormatException(error); } }
private static void ResizeImage(ResizeWorkerItem item) { try { CoreContext.TenantManager.SetCurrentTenant(item.TenantId); var data = item.Data; using (var stream = new MemoryStream(data)) using (var img = Image.FromStream(stream)) { var imgFormat = img.RawFormat; if (item.Size != img.Size) { using (var img2 = item.Settings.IsDefault ? CommonPhotoManager.DoThumbnail(img, item.Size, true, true, true) : UserPhotoThumbnailManager.GetBitmap(img, item.Size, item.Settings)) { data = CommonPhotoManager.SaveToBytes(img2); } } else { data = CommonPhotoManager.SaveToBytes(img); } var widening = CommonPhotoManager.GetImgFormatName(imgFormat); var fileName = string.Format("{0}_size_{1}-{2}.{3}", item.UserId, item.Size.Width, item.Size.Height, widening); using (var stream2 = new MemoryStream(data)) { item.DataStore.Save(fileName, stream2).ToString(); AddToCache(item.UserId, item.Size, fileName); } } } catch (ArgumentException error) { throw new UnknownImageFormatException(error); } }
private static void ExecResizeImage(ResizeWorkerItem resizeWorkerItem) { foreach (var fotoSize in resizeWorkerItem.RequireFotoSize) { var data = resizeWorkerItem.ImageData; using (var stream = new MemoryStream(data)) using (var img = new Bitmap(stream)) { var imgFormat = img.RawFormat; if (fotoSize != img.Size) { using (var img2 = CommonPhotoManager.DoThumbnail(img, fotoSize, false, false, false)) { data = CommonPhotoManager.SaveToBytes(img2, Global.GetImgFormatName(imgFormat)); } } else { data = Global.SaveToBytes(img); } var fileExtension = String.Concat("." + Global.GetImgFormatName(imgFormat)); var photoPath = !resizeWorkerItem.UploadOnly ? BuildFilePath(resizeWorkerItem.ContactID, fotoSize, fileExtension) : BuildFileTmpPath(resizeWorkerItem.ContactID, fotoSize, fileExtension, resizeWorkerItem.TmpDirName); using (var fileStream = new MemoryStream(data)) { var photoUri = resizeWorkerItem.DataStore.Save(photoPath, fileStream).ToString(); photoUri = String.Format("{0}?cd={1}", photoUri, DateTime.UtcNow.Ticks); if (!resizeWorkerItem.UploadOnly) { ToCache(resizeWorkerItem.ContactID, photoUri, fotoSize); } } } } }
private static void ResizeImage(ResizeWorkerItem item) { try { var data = item.Data; using (var stream = new MemoryStream(data)) using (var img = Image.FromStream(stream)) { var imgFormat = img.RawFormat; if (item.Size != img.Size) { using (var img2 = CommonPhotoManager.DoThumbnail(img, item.Size, true, true, true)) { data = CommonPhotoManager.SaveToBytes(img2); } } else { data = CommonPhotoManager.SaveToBytes(img); } var widening = CommonPhotoManager.GetImgFormatName(imgFormat); var trueFileName = string.Format("{0}{1}_size_{2}-{3}.{4}", (item.ModuleId == Guid.Empty ? "" : item.ModuleId.ToString()), item.UserId, item.Size.Width, item.Size.Height, widening); using (var stream2 = new MemoryStream(data)) { var photoUrl = item.DataStore.Save(trueFileName, stream2).ToString(); //NOTE: Update cache here var fileName = Path.GetFileName(photoUrl); AddToCache(item.UserId, item.Size, fileName, true); } } } catch (ArgumentException error) { throw new UnknownImageFormatException(error); } }
public static string GetSizedTempPhotoAbsoluteWebPath(string fileName, int newWidth, int newHeight) { var store = GetDataStore(); if (store.IsFile(_tempDomainName, fileName)) { using (var s = store.GetReadStream(_tempDomainName, fileName)) using (var img = Image.FromStream(s)) { var imgFormat = img.RawFormat; byte[] data; if (img.Width != newWidth || img.Height != newHeight) { using (var img2 = CommonPhotoManager.DoThumbnail(img, new Size(newWidth, newHeight), true, true, true)) { data = CommonPhotoManager.SaveToBytes(img2); } } else { data = CommonPhotoManager.SaveToBytes(img); } var widening = CommonPhotoManager.GetImgFormatName(imgFormat); var index = fileName.LastIndexOf('.'); var fileNameWithoutExt = (index != -1) ? fileName.Substring(0, index) : fileName; var trueFileName = fileNameWithoutExt + "_size_" + newWidth.ToString() + "-" + newHeight.ToString() + "." + widening; using (var stream = new MemoryStream(data)) { return(store.Save(_tempDomainName, trueFileName, stream).ToString()); } } } return(GetDefaultPhotoAbsoluteWebPath(new Size(newWidth, newHeight))); }