public ActionResult Upload(HttpPostedFileWrapper uplFile) { try { var filePath = $"/Content/files/{uplFile.FileName}"; PreviewCreator.CreateAndSavePreview( uplFile.InputStream, PreviewCreator.ReduceSize(uplFile.InputStream, 600), Server.MapPath(filePath)); var filePreviewPath = $"/Content/files/previews/{uplFile.FileName}"; PreviewCreator.CreateAndSavePreview( uplFile.InputStream, new Size(300, 225), Server.MapPath(filePreviewPath)); return(Json(new { success = true, result = "error", data = new { filePath, filePreviewPath } })); } catch { return(Json(new { error = "Нужно загрузить изображение", success = false })); } }
private string CreatePreviewHtml() { string folderPath = Path.GetDirectoryName(_markdownPath); PreviewCreator.CreateHtmlPreviewFileFromMarkdown(txtMarkdown.Text, folderPath + "/tmp.html"); return(folderPath + "/tmp.html"); }
public void TestPreviewCreator() { IPreviewCreator previewCreator = new PreviewCreator(); var filename = "1.jpg"; using var file = File.OpenRead($"TestImages/{filename}"); using var preview = new MemoryStream(); previewCreator.CreatePreview(file, preview); Assert.Greater(preview.Length, 0); Assert.AreNotEqual(file.Length, preview.Length); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); if (!Application.isPlaying) { if (GUILayout.Button("Save to preview")) { PreviewCreator pc = target as PreviewCreator; if (target != null) { pc.SaveToPriview(); } } } }
public ActionResult Export(string uri) { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri); webRequest.Method = "GET"; webRequest.KeepAlive = false; webRequest.PreAuthenticate = false; webRequest.Timeout = 1000; var response = webRequest.GetResponse(); var stream = response.GetResponseStream(); var previewIconSize = Config.IconSizes.FirstOrDefault(c => c.Name == "AvatarSize"); var filePreviewPath = Path.Combine("/Content/files/previews", Guid.NewGuid().ToString("N") + ".jpg"); if (previewIconSize != null) { PreviewCreator.CreateAndSavePreview(stream, new Size(previewIconSize.Width, previewIconSize.Height), Server.MapPath(filePreviewPath)); } return(Content("OK")); }
public ActionResult Upload(HttpPostedFileWrapper qqfile) { var extension = Path.GetExtension(qqfile.FileName); if (!string.IsNullOrWhiteSpace(extension)) { var mimeType = Config.MimeTypes.FirstOrDefault(p => string.Compare(p.Extension, extension, 0) == 0); //если изображение if (mimeType != null && PreviewCreator.SupportMimeType(mimeType.Name)) { //тут сохраняем в файл var filePath = Path.Combine("/Content/files", Path.GetFileName(qqfile.FileName)); qqfile.SaveAs(Server.MapPath(filePath)); var filePreviewPath = Path.Combine("/Content/files/previews", Path.GetFileName(qqfile.FileName)); var previewIconSize = Config.IconSizes.FirstOrDefault(c => c.Name == "AvatarSize"); if (previewIconSize != null) { PreviewCreator.CreateAndSavePreview(qqfile.InputStream, new Size(previewIconSize.Width, previewIconSize.Height), Server.MapPath(filePreviewPath)); } return(Json(new { success = true, result = "error", data = new { filePath, filePreviewPath } })); } } return(Json(new { error = "Нужно загрузить изображение", success = false })); }
public ActionResult EditApartmentPhoto(EditApartmentPhotoViewResult newApartment) { if (ModelState.IsValid) { if (newApartment.InputImages != null) { Apartment apartment = _apartmentRepository.GetApartment(newApartment.ApartmentId); var Photos = _apartmentRepository.GetApartmentPhotos(apartment); var HasDafaultPhoto = true; if (Photos.Count == 0) { HasDafaultPhoto = false; } foreach (var photo in newApartment.InputImages.Where(m => m != null)) { int height, width, max; int centerx, centery; int offsetx, offsety; using (System.Drawing.Image image = System.Drawing.Image.FromStream(photo.InputStream, true, true)) { height = image.Height; width = image.Width; centerx = width / 2; centery = height / 2; if (height > width) { max = width; offsetx = 0; offsety = centery - max / 2; } else { max = height; offsety = 0; offsetx = centerx - max / 2; } } ApartmentPhoto Photo = new ApartmentPhoto { ApartmentId = newApartment.ApartmentId, Links = new List <ApartmentPhotoLink>() }; Photo.Links.Add(new ApartmentPhotoLink { Link = PreviewCreator.SaveImage(photo.InputStream), TypeId = 1 }); Photo.Links.Add(new ApartmentPhotoLink { Link = PreviewCreator.SaveImageAndResize(photo.InputStream, (int)offsetx, (int)offsety, (int)max, (int)max, new System.Drawing.Size(550, 550)), TypeId = 2 }); Photo.Links.Add(new ApartmentPhotoLink { Link = PreviewCreator.SaveImageAndResize(photo.InputStream, (int)offsetx, (int)offsety, (int)max, (int)max, new System.Drawing.Size(100, 100)), TypeId = 3 }); _apartmentRepository.AddApartmentPhoto(apartment, Photo); if (!HasDafaultPhoto) { _apartmentRepository.SetApartmentDefaultPhoto(apartment, Photo); } HasDafaultPhoto = true; TempData["toastrMessage"] = String.Format("Квартира изменена"); TempData["toastrType"] = "success"; } } } else { } return(RedirectToAction("EditApartmentPhoto")); }
public ActionResult ProfileEditAvatar(ProfileEditResult newProfile, double?cropx = 0, double?cropy = 0, double?croph = 0, double?cropw = 0) { if ((ModelState.IsValid)) { if (newProfile.inputImage != null) { newProfile.inputImage = newProfile.inputImage ?? Request.Files["inputImage"]; if (newProfile.inputImage != null) { var extension = Path.GetExtension(newProfile.inputImage.FileName); if (!string.IsNullOrWhiteSpace(extension)) { if (newProfile.Profile.ImageLink != null) { PreviewCreator.RemoveImage(System.Web.Hosting.HostingEnvironment.MapPath(newProfile.Profile.ImageLink)); } if (newProfile.Profile.ImageAvatarLink != null) { PreviewCreator.RemoveImage(System.Web.Hosting.HostingEnvironment.MapPath(newProfile.Profile.ImageAvatarLink)); } if (newProfile.Profile.ImageAvatarBigLink != null) { PreviewCreator.RemoveImage(System.Web.Hosting.HostingEnvironment.MapPath(newProfile.Profile.ImageAvatarBigLink)); } newProfile.Profile.ImageType = ("image/" + extension).Replace(".", ""); newProfile.Profile.ImageLink = PreviewCreator.SaveImage(newProfile.inputImage.InputStream); newProfile.Profile.ImageAvatarType = ("image/" + ".jpg").Replace(".", ""); newProfile.Profile.ImageAvatarLink = PreviewCreator.SaveImageAndResize(newProfile.inputImage.InputStream, (int)cropx, (int)cropy, (int)cropw, (int)croph, new Size(48, 48)); newProfile.Profile.ImageAvatarBigType = ("image/" + ".jpg").Replace(".", ""); newProfile.Profile.ImageAvatarBigLink = PreviewCreator.SaveImageAndResize(newProfile.inputImage.InputStream, (int)cropx, (int)cropy, (int)cropw, (int)croph, new Size(550, 550)); } } } else { if ((newProfile.Profile.ImageLink != null) && (cropx != 0) && (cropy != 0) && (cropw != 0) && (croph != 0)) { using (var fileStream = new FileStream(Server.MapPath(newProfile.Profile.ImageLink), FileMode.Open, FileAccess.Read)) { if (newProfile.Profile.ImageAvatarLink != null) { PreviewCreator.RemoveImage(System.Web.Hosting.HostingEnvironment.MapPath(newProfile.Profile.ImageAvatarLink)); } if (newProfile.Profile.ImageAvatarBigLink != null) { PreviewCreator.RemoveImage(System.Web.Hosting.HostingEnvironment.MapPath(newProfile.Profile.ImageAvatarBigLink)); } newProfile.Profile.ImageAvatarType = ("image/" + ".jpg").Replace(".", ""); newProfile.Profile.ImageAvatarLink = PreviewCreator.SaveImageAndResize(fileStream, (int)cropx, (int)cropy, (int)cropw, (int)croph, new Size(48, 48)); newProfile.Profile.ImageAvatarBigType = ("image/" + ".jpg").Replace(".", ""); newProfile.Profile.ImageAvatarBigLink = PreviewCreator.SaveImageAndResize(fileStream, (int)cropx, (int)cropy, (int)cropw, (int)croph, new Size(550, 550));; } } } newProfile.Profile.New = false; _profileService.UpdateProfile(newProfile.Profile, ProfileUpdateMode.Avatar); UpdateProfileMEssage(); } return(View(newProfile)); }