public bool CreateThumbnail2(string thumbnailFolder, string filename) { if (!Directory.Exists(thumbnailFolder)) { return(false); } if (!File.Exists(filename)) { return(false); } FileInfo fInfo = new FileInfo(filename); string namePart = fInfo.Name.Replace(fInfo.Extension, ""); try { ImageProcessor.ImageFactory mFact = new ImageProcessor.ImageFactory(); ImageProcessor.Imaging.Formats.JpegFormat format = new ImageProcessor.Imaging.Formats.JpegFormat(); format.Quality = 100; mFact.Load(filename).Resize(new Size(300, 300)).Format(format).BackgroundColor(Color.White).Save(thumbnailFolder + @"\" + namePart + ".jpg"); return(true); } catch { return(false); } }
private static void Main() { using (var imageFactory = new ImageProcessor.ImageFactory()) { imageFactory.Load("skybox.png"); var size = imageFactory.Image.Width / 4; var directory = Directory.GetCurrentDirectory(); imageFactory .Crop(new Rectangle(size, 0, size, size)) .Save(Path.Combine(directory, "skybox-top.png")) .Reset() .Crop(new Rectangle(0, size, size, size)) .Save(Path.Combine(directory, "skybox-left.png")) .Reset() .Crop(new Rectangle(size, size, size, size)) .Save(Path.Combine(directory, "skybox-front.png")) .Reset() .Crop(new Rectangle(size * 2, size, size, size)) .Save(Path.Combine(directory, "skybox-right.png")) .Reset() .Crop(new Rectangle(size * 3, size, size, size)) .Save(Path.Combine(directory, "skybox-back.png")) .Reset() .Crop(new Rectangle(size, size * 2, size, size)) .Save(Path.Combine(directory, "skybox-bottom.png")); } }
public static void ProcessThumbnail(HttpPostedFileBase file, string destPath) { try { using (var imgFactory = new ImageProcessor.ImageFactory()) { imgFactory.Load(file.InputStream); imgFactory.Format(new ImageProcessor.Imaging.Formats.JpegFormat() { Quality = 100 }); if (imgFactory.Image.Size.Width > 256) { imgFactory.Resize(new System.Drawing.Size(256, imgFactory.Image.Size.Height * 256 / imgFactory.Image.Width)); } if (imgFactory.Image.Size.Height > imgFactory.Image.Size.Width) { imgFactory.Crop(new System.Drawing.Rectangle(0, 0, imgFactory.Image.Size.Width, imgFactory.Image.Size.Width)); } else if (imgFactory.Image.Size.Width > imgFactory.Image.Height) { imgFactory.Crop(new System.Drawing.Rectangle(0, 0, imgFactory.Image.Size.Height, imgFactory.Image.Size.Height)); } imgFactory.Resize(new System.Drawing.Size(256, 256)); imgFactory.Save(destPath); } } catch { } }
private Task ProcessMemeballMeme(string text, MemoryStream stream) { using (ImageProcessor.ImageFactory ifact = new ImageProcessor.ImageFactory()) { //TEXT WILL BE 32 CHARACTERS PER LINE, AT A 30 PIXEL HEIGHT IN ARIAL FONT //IMAGE ITSELF IS 450 PIXELS HIGH, ADD 34 PX PER LINE OF TEXT //TOTAL CANVAS IS 850 PX HIGH, String[] words = text.Split(' '); ifact.Load($"resources/mball/{words[0]}.png"); string memetext = ""; int lines = 0; string currentline = ""; for (int i = 1; i < words.Length; ++i) { string word = words[i]; if ((currentline + word).Length >= 32) { memetext += (currentline + "\n"); ++lines; currentline = ""; } currentline += (word + " "); } memetext += currentline; TextLayer tl = new TextLayer(); tl.Position = new Point(68, (380 - (34 * lines))); tl.FontSize = 30; tl.FontFamily = FontFamily.GenericSansSerif; tl.Text = memetext; tl.FontColor = System.Drawing.Color.Black; ifact.Watermark(tl); ifact.Crop(new Rectangle(0, (374 - (34 * lines)), 592, 850 - (374 - (34 * lines)))); ifact.Save(stream); return(Task.FromResult <object>(null)); } }
private byte[] bytesFromFileName(string path) { using (var stream = new MemoryStream()) { using (var factory = new ImageProcessor.ImageFactory()) { factory.Load(path).Resize(new ResizeLayer(new System.Drawing.Size(77, 96), ResizeMode.Crop)).Save(stream); return stream.ToArray(); } } }
public bool RotateImage(string filePath, int degree) { try { ImageProcessor.ImageFactory mFact = new ImageProcessor.ImageFactory(); mFact.Load(filePath); mFact.Rotate(degree); mFact.Save(filePath); return(true); } catch { return(false); } }
public string resizeImage(int maxWidth, int maxHeight, string fullPath, string path) { string physicalPath = fullPath; string nameFile = path; //return resizeImage(Config.imgWidthProduct, Config.imgHeightProduct, physicalPath + nameFile, Config.ProductImagePath + "/" + nameFile); ImageProcessor.ImageFactory iFF = new ImageProcessor.ImageFactory(); ////Tạo ra file thumbail không có watermark Size size1 = new Size(Config.imgWidthNews, Config.imgHeightNews); iFF.Load(physicalPath + nameFile).Resize(size1).BackgroundColor(Color.WhiteSmoke).Save(physicalPath + nameFile); //iFF.Load(physicalPath + nameFile).BackgroundColor(Color.WhiteSmoke).Resize(size1).Save(physicalPath + nameFile); return("ok"); }
public string Upload(ImageData upload) { string path = Server.MapPath(@"~/App_Data/network.json"); var activation = new SigmoidActivation(); var outputList = Enumerable.Range(0, 10).Select(i => i.ToString(CultureInfo.InvariantCulture)).ToList(); var network = new Network(activation, 784, outputList, path); string raw = upload.base64Image; byte[] data = Convert.FromBase64String(raw.Substring(raw.IndexOf(',') + 1)); Bitmap bitmap; const int imageSize = 28; using (var inStream = new MemoryStream(data, 0, data.Length)) { using (var outstream = new MemoryStream()) { using (var imagefactory = new ImageProcessor.ImageFactory()) { imagefactory.Load(inStream) .Resize(new ResizeLayer(new Size(imageSize, imageSize), ResizeMode.Stretch)) .Filter(MatrixFilters.GreyScale) .Filter(MatrixFilters.Invert) .Flip(true) .Rotate(90) .Save(outstream); } outstream.Position = 0; bitmap = new Bitmap(outstream); } } var inputs = new List <double>(); for (int x = 0; x < imageSize; x++) { for (int y = 0; y < imageSize; y++) { Color pixel = bitmap.GetPixel(x, y); inputs.Add(((pixel.R + pixel.G + pixel.B) / 3.0d) / 255.0d); } } network.UpdateNetwork(inputs); string result = network.GetMostLikelyAnswer(); return(string.Format("I think it looks like a {0}", result)); }
private Stream GetCroppedImage(string extension, int width, int height, float cx, float cy, MediaItem mediaItem) { var outputStrm = new MemoryStream(); var mediaStrm = mediaItem.GetMediaStream(); var img = Image.FromStream(mediaStrm); var proc = new ImageProcessor.ImageFactory(); proc.Load(img); var axis = new float[] { cy, cx }; proc = proc.Resize(new ResizeLayer(new Size(width, height), ResizeMode.Crop, AnchorPosition.Center, true, centerCoordinates: axis)); proc.Save(outputStrm); return(outputStrm); }
public static void Display(User user, DiscordClient client) { byte[] avatar = null; using (var wc = new System.Net.WebClient()) { avatar = (user.AvatarUrl == null) ? null : wc.DownloadData(user.AvatarUrl); if (avatar == null) { client.GetChannel( (from channel in Config.INSTANCE.primaryChannels where channel.server_id == user.Server.Id select channel.channel_id).First() ).SendMessage("Welcome new comrade" + user.Mention); return; } } var astream = new MemoryStream(avatar); Image ai = Image.FromStream(astream); var outstream = new MemoryStream(); using (var ifact = new ImageProcessor.ImageFactory()) { //159,204 image size 283x283 ImageLayer ilay = new ImageLayer() { Image = ai, Size = new Size(283, 283), Position = new Point(159, 204) }; ifact.Load("resources/welcome.jpg"); ifact.Overlay(ilay); System.Drawing.Color yellow = System.Drawing.Color.FromArgb(208, 190, 25); TextLayer uname = new TextLayer() { Position = new Point(108, 512), FontFamily = FontFamily.GenericSansSerif, FontSize = 30, Text = user.Nickname, FontColor = yellow }; ifact.Watermark(uname); ifact.Save(outstream); } Channel general = client.GetChannel((from channel in Config.INSTANCE.primaryChannels where channel.server_id == user.Server.Id select channel.channel_id).First()); general.SendMessage("Welcome new comrade " + user.Mention); general.SendFile("welcome.jpg", outstream); ModerationLog.LogToPublic($"User {user} joined.", client.GetServer(user.Server.Id)); }
private static void LoadImageAndReport(LoadMode mode, string filename) { switch (mode) { case LoadMode.System: using (var image = System.Drawing.Image.FromFile(filename)) { Console.WriteLine("{0} image size = {1}w by {2}h", System.IO.Path.GetFileName(filename), image.Width, image.Height); MemoryManagement.CheckMemory("With image loaded", true); } break; case LoadMode.Palaso: using (var image = SIL.Windows.Forms.ImageToolbox.PalasoImage.FromFile(filename)) { Console.WriteLine("{0} image size = {1}w by {2}h", System.IO.Path.GetFileName(filename), image.Image.Width, image.Image.Height); MemoryManagement.CheckMemory("With image loaded", true); } break; case LoadMode.ImageProcessor: using (var factory = new ImageProcessor.ImageFactory(true)) { factory.Load(filename); Console.WriteLine("{0} image size = {1}w by {2}h", System.IO.Path.GetFileName(filename), factory.Image.Width, factory.Image.Height); MemoryManagement.CheckMemory("With image loaded", true); } break; case LoadMode.ImageSharp: using (var image = SixLabors.ImageSharp.Image.Load(filename)) { Console.WriteLine("{0} image size = {1}w by {2}h", System.IO.Path.GetFileName(filename), image.Width, image.Height); MemoryManagement.CheckMemory("With image loaded", true); } break; } }
public static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("Specify input image"); return; } var fac = new ImageProcessor.ImageFactory(true); fac.Load(args[0]); var fb = new ImageProcessor.Imaging.FastBitmap(fac.Image); int iw = fb.Width; int ih = fb.Height; double min = double.MaxValue; double max = double.MinValue; int samples = 100; int skip = Math.Min(iw, ih) / samples; /* * for(int y=0; y<ih; y++) { * for(int x=0; x<iw; x++) { * var c = fb.GetPixel(x,y); * double dist = Math.Sqrt(c.R*c.R + c.G*c.G + c.B*c.B); * if (dist < min) { min = dist; } * if (dist > max) { max = dist; } * } * } * * Console.WriteLine("max= "+max+" min= "+min); */ var topsamp = new double[samples]; var topcord = new int[samples]; int topmax = ih / 2; for (int s = 0; s < samples; s++) { int x = s * iw / samples; double maxdiff = double.MinValue; double lastdist = 0; for (var y = 0; y < topmax; y++) { var c = fb.GetPixel(x, y); double dist = Math.Sqrt(c.R * c.R + c.G * c.G + c.B * c.B); if (y == 0) { lastdist = dist; continue; } double diff = Math.Abs(lastdist - dist); lastdist = dist; if (diff > maxdiff) { maxdiff = diff; topsamp[s] = diff; topcord[s] = y; } } } for (int s = 0; s < samples; s++) { //Console.WriteLine(s+" ["+topcord[s]+","+topsamp[s]+"]"); Console.WriteLine(topcord[s] + "," + topsamp[s]); } }
public ActionResult uploadimg() { if (Config.getCookie("logged") == "") { return(Json(new { Message = "Error" }, JsonRequestBehavior.AllowGet)); } var fName = ""; try { foreach (string fileName in Request.Files) { HttpPostedFileBase file = Request.Files[fileName]; //Save file content goes here if (file != null && file.ContentLength > 0) { var originalDirectory = new DirectoryInfo(string.Format("{0}images\\news", Server.MapPath(@"\"))); string strDay = DateTime.Now.ToString("yyyyMM"); string pathString = System.IO.Path.Combine(originalDirectory.ToString(), strDay); var _fileName = Guid.NewGuid().ToString("N") + ".jpg"; bool isExists = System.IO.Directory.Exists(pathString); if (!isExists) { System.IO.Directory.CreateDirectory(pathString); } var path = string.Format("{0}\\{1}", pathString, _fileName); //System.Drawing.Image bm = System.Drawing.Image.FromStream(file.InputStream); // Thay đổi kích thước ảnh //bm = ResizeBitmap((Bitmap)bm, 100, 100); /// new width, height //// Giảm dung lượng ảnh trước khi lưu //ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); //ImageCodecInfo ici = null; //foreach (ImageCodecInfo codec in codecs) //{ // if (codec.MimeType == "image/jpeg") // ici = codec; //} //EncoderParameters ep = new EncoderParameters(); //ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)80); //bm.Save(path, ici, ep); //bm.Save(path); file.SaveAs(path); FileInfo f2 = new FileInfo(path); if (f2.Length > 100000) { int percent = 50; if (f2.Length > 1000000) { percent = 10; } else if (f2.Length > 500000) { percent = 20; } else if (f2.Length > 300000) { percent = 30; } ImageProcessor.ImageFactory iFF = new ImageProcessor.ImageFactory(); iFF.Load(path).Quality(percent).Save(path); } fName = "/images/news/" + strDay + "/" + _fileName; } } } catch (Exception ex) { } return(Json(new { Message = fName }, JsonRequestBehavior.AllowGet)); }
private void CoverEditForm_Shown(object sender, System.EventArgs e) { UseWaitCursor = true; var keyParts = releaseKey.Split(MainForm.Separator); var galaxyCacheRoot = Path.Combine(parent.galaxyRootPath, keyParts[0], keyParts[1]); string bannerFilename; string iconFilename; using (var db = new GalaxyDb()) { bannerFilename = db.WebCacheResources .Where(r => r.WebCache.ReleaseKey == releaseKey && r.WebCache.UserId == userId && r.WebCacheResourceTypeId == WebCacheResourceType.Background ) .Select(r => r.Filename) .FirstOrDefault(); iconFilename = db.WebCacheResources .Where(r => r.WebCache.ReleaseKey == releaseKey && r.WebCache.UserId == userId && r.WebCacheResourceTypeId == WebCacheResourceType.SquareIcon ) .Select(r => r.Filename) .FirstOrDefault(); } using (var imgFactory = new ImageProcessor.ImageFactory()) { // cover 342x482, ~7:5 galaxyCoverPicture.Image = pictureBox.Image; var coverPath = Path.Combine(parent.steamRootPath, $"{keyParts[1]}_library_600x900.jpg"); if (File.Exists(coverPath)) { try { using (var img = imgFactory.Load(coverPath).Resize(new ResizeLayer(new Size(342, 482), ResizeMode.Crop))) // 600x900 steamCoverPicture.Image = (Image)img.Image.Clone(); } catch { } } // banner 1600x650 if (!string.IsNullOrEmpty(bannerFilename)) { bannerFilename = Path.Combine(galaxyCacheRoot, bannerFilename); if (File.Exists(bannerFilename)) { try { using (var img = imgFactory.Load(bannerFilename)) galaxyBackgroundPicture.Image = (Image)img.Image.Clone(); } catch { } } } var steamBannerPath = Path.Combine(parent.steamRootPath, $"{keyParts[1]}_library_hero.jpg"); if (File.Exists(steamBannerPath)) { try { using (var img = imgFactory.Load(steamBannerPath).Resize(new ResizeLayer(new Size(1600, 650), ResizeMode.Crop))) // 1920x620 steamBackgroundPicture.Image = (Image)img.Image.Clone(); } catch { } } // icon 112x112 if (!string.IsNullOrEmpty(iconFilename)) { iconFilename = Path.Combine(galaxyCacheRoot, iconFilename); if (File.Exists(iconFilename)) { try { using (var img = imgFactory.Load(iconFilename)) galaxyIconPicture.Image = (Image)img.Image.Clone(); } catch { } } } var steamIconPath = Path.Combine(parent.steamRootPath, $"{keyParts[1]}_library_600x900.jpg"); if (File.Exists(steamIconPath)) { try { using (var img = imgFactory.Load(steamIconPath).EntropyCrop().Resize(new ResizeLayer(new Size(112, 112), ResizeMode.Crop))) // 1920x620 steamIconPicture.Image = (Image)img.Image.Clone(); } catch { } } } UseWaitCursor = false; }
private void okButton_Click(object sender, System.EventArgs e) { var keyParts = releaseKey.Split(MainForm.Separator); var galaxyCacheRoot = Path.Combine(parent.galaxyRootPath, keyParts[0], keyParts[1]); if (!Directory.Exists(galaxyCacheRoot)) { Directory.CreateDirectory(galaxyCacheRoot); } const int defaultQuality = 90; const bool deleteOldFiles = false; using (var imgFactory = new ImageProcessor.ImageFactory()) { if (steamCoverSelect.Checked) { pictureBox.Image = steamCoverPicture.Image; string filename; using (var stream = new MemoryStream()) { using (var img = imgFactory.Load(steamCoverPicture.Image).Format(new WebPFormat { Quality = defaultQuality })) img.Save(stream); stream.Seek(0, SeekOrigin.Begin); using (var sha = SHA256.Create()) filename = string.Concat(sha.ComputeHash(stream).Select(b => b.ToString("x2"))); filename += "_glx_vertical_cover.webp"; stream.Seek(0, SeekOrigin.Begin); var outputFilename = Path.Combine(galaxyCacheRoot, filename); File.WriteAllBytes(outputFilename, stream.ToArray()); } using (var db = new GalaxyDb()) { var existingCover = db.WebCacheResources.FirstOrDefault(r => r.WebCache.ReleaseKey == releaseKey && r.WebCache.UserId == userId && r.WebCacheResourceTypeId == WebCacheResourceType.VerticalCover); if (existingCover == null) { var webCache = db.WebCache.FirstOrDefault(r => r.ReleaseKey == releaseKey && r.UserId == userId); if (webCache == null) { webCache = db.Add(new WebCache { ReleaseKey = releaseKey, UserId = userId, }).Entity; } db.WebCacheResources.Add(new WebCacheResources { WebCacheId = webCache.Id, WebCacheResourceTypeId = WebCacheResourceType.VerticalCover, Filename = filename, }); } else { var existingImg = Path.Combine(galaxyCacheRoot, existingCover.Filename); if (deleteOldFiles && File.Exists(existingImg)) { try { File.Delete(existingImg); } catch { } } existingCover.Filename = filename; } db.SaveChanges(); } } if (steamBackgroundSelect.Checked) { galaxyBackgroundPicture.Image = steamBackgroundPicture.Image; string filename; using (var stream = new MemoryStream()) { using (var img = imgFactory.Load(steamBackgroundPicture.Image).Format(new WebPFormat { Quality = defaultQuality })) img.Save(stream); stream.Seek(0, SeekOrigin.Begin); using (var sha = SHA256.Create()) filename = string.Concat(sha.ComputeHash(stream).Select(b => b.ToString("x2"))); filename += "_glx_bg_top_padding_7.webp"; stream.Seek(0, SeekOrigin.Begin); var outputFilename = Path.Combine(galaxyCacheRoot, filename); File.WriteAllBytes(outputFilename, stream.ToArray()); } using (var db = new GalaxyDb()) { var existingBackground = db.WebCacheResources .FirstOrDefault(r => r.WebCache.ReleaseKey == releaseKey && r.WebCache.UserId == userId && r.WebCacheResourceTypeId == WebCacheResourceType.Background); if (existingBackground == null) { var webCache = db.WebCache.FirstOrDefault(r => r.ReleaseKey == releaseKey && r.UserId == userId); if (webCache == null) { webCache = db.Add(new WebCache { ReleaseKey = releaseKey, UserId = userId, }).Entity; } db.WebCacheResources.Add(new WebCacheResources { WebCacheId = webCache.Id, WebCacheResourceTypeId = WebCacheResourceType.Background, Filename = filename, }); } else { var existingImg = Path.Combine(galaxyCacheRoot, existingBackground.Filename); if (deleteOldFiles && File.Exists(existingImg)) { try { File.Delete(existingImg); } catch { } } existingBackground.Filename = filename; } db.SaveChanges(); } } if (steamIconSelect.Checked) { galaxyIconPicture.Image = steamIconPicture.Image; string filename; using (var stream = new MemoryStream()) { using (var img = imgFactory.Load(steamIconPicture.Image).Format(new WebPFormat { Quality = defaultQuality })) img.Save(stream); stream.Seek(0, SeekOrigin.Begin); using (var sha = SHA256.Create()) filename = string.Concat(sha.ComputeHash(stream).Select(b => b.ToString("x2"))); filename += "_glx_square_icon_v2.webp"; stream.Seek(0, SeekOrigin.Begin); var outputFilename = Path.Combine(galaxyCacheRoot, filename); File.WriteAllBytes(outputFilename, stream.ToArray()); } using (var db = new GalaxyDb()) { var existingIcon = db.WebCacheResources .FirstOrDefault(r => r.WebCache.ReleaseKey == releaseKey && r.WebCache.UserId == userId && r.WebCacheResourceTypeId == WebCacheResourceType.SquareIcon); if (existingIcon == null) { var webCache = db.WebCache.FirstOrDefault(r => r.ReleaseKey == releaseKey && r.UserId == userId); if (webCache == null) { webCache = db.Add(new WebCache { ReleaseKey = releaseKey, UserId = userId, }).Entity; } db.WebCacheResources.Add(new WebCacheResources { WebCacheId = webCache.Id, WebCacheResourceTypeId = WebCacheResourceType.SquareIcon, Filename = filename, }); } else { var existingImg = Path.Combine(galaxyCacheRoot, existingIcon.Filename); if (deleteOldFiles && File.Exists(existingImg)) { try { File.Delete(existingImg); } catch { } } existingIcon.Filename = filename; } db.SaveChanges(); } } } DialogResult = DialogResult.OK; Close(); }
// !MAIN! Generating Method -> through button2 ( Generate BTN) private void button2_Click(object sender, EventArgs e) { targerImg = new ImageProcessor.ImageFactory(); try { if (targetpicture != null) { targerImg.Load(targetpicture); } else { targerImg.Load(previewbox.Image); } } catch (Exception ex) { MessageBox.Show("You have not loaded image! Please click 'Load Image' button", "Ops!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } string path = System.IO.Path.GetRandomFileName().ToString() + ".png"; try { if (comboBox1.SelectedIndex >= 0) { switch (comboBox1.SelectedIndex) { case 0: targerImg.Filter(ImageProcessor.Imaging.Filters.Photo.MatrixFilters.BlackWhite); Debug.WriteLine(comboBox1.SelectedText); break; case 1: targerImg.Filter(ImageProcessor.Imaging.Filters.Photo.MatrixFilters.Comic); break; case 2: targerImg.Filter(ImageProcessor.Imaging.Filters.Photo.MatrixFilters.Gotham); break; case 3: targerImg.Filter(ImageProcessor.Imaging.Filters.Photo.MatrixFilters.GreyScale); break; case 4: targerImg.Filter(ImageProcessor.Imaging.Filters.Photo.MatrixFilters.HiSatch); break; case 5: targerImg.Filter(ImageProcessor.Imaging.Filters.Photo.MatrixFilters.Invert); break; case 6: targerImg.Filter(ImageProcessor.Imaging.Filters.Photo.MatrixFilters.Lomograph); break; case 7: targerImg.Filter(ImageProcessor.Imaging.Filters.Photo.MatrixFilters.LoSatch); break; case 8: targerImg.Filter(ImageProcessor.Imaging.Filters.Photo.MatrixFilters.Polaroid); break; case 9: targerImg.Filter(ImageProcessor.Imaging.Filters.Photo.MatrixFilters.Sepia); break; } } if (blur_cb.Checked == true) { targerImg.GaussianBlur(10); } if (vignette_cb.Checked == true) { if (colorDialog_Vignette.Color == null) { targerImg.Vignette(DEFAULT_VIGNETTE_COLOR); } else { targerImg.Vignette(colorDialog_Vignette.Color); } } if (round_cb.Checked == true) { targerImg.RoundedCorners(25); } if (richTextBox1.Text != "") { using (ImageProcessor.Imaging.TextLayer Text = new ImageProcessor.Imaging.TextLayer()) { Text.Text = richTextBox1.Text.ToString(); if (checkBox1.Checked == true) { Text.DropShadow = true; } else { Text.DropShadow = false; } Text.FontSize = Convert.ToInt32(fontDialog1.Font.Size); Text.FontColor = colorDialog1.Color; Text.FontFamily = fontDialog1.Font.FontFamily; targerImg.Watermark(Text); } } targerImg.Save(System.IO.Path.GetTempPath().ToString() + path); pictureBox1.Load(System.IO.Path.GetTempPath().ToString() + path); } catch (Exception ex) { } }
public HttpResponseMessage ImageUpload() { var httpRequest = HttpContext.Current.Request; var allowedSuffixes = new[] { ".jpg", ".jpeg", ".png", ".gif" }; dynamic result = new ExpandoObject(); if (httpRequest.Files.Count > 0) { var fileName = string.Empty; var guid = Guid.NewGuid(); foreach (string file in httpRequest.Files) { var postedFile = httpRequest.Files[file]; if (postedFile == null) { continue; } fileName = Path.GetFileName(postedFile.FileName); // only allow files with certain extensions if (allowedSuffixes.InvariantContains(fileName.Substring(fileName.LastIndexOf(".", StringComparison.Ordinal))) == false) { continue; } var updir = new DirectoryInfo(HttpContext.Current.Server.MapPath("/media/upload/" + guid)); if (!updir.Exists) { updir.Create(); } var filePath = string.Format("{0}/{1}", updir.FullName, fileName); // Note: resizing with ImageProcessor also removes all Exif data, which is a good thing var imageFactory = new ImageProcessor.ImageFactory(); imageFactory.Load(postedFile.InputStream); var resizeLayer = new ResizeLayer(resizeMode: ResizeMode.Crop, upscale: true, size: new Size(500, 500)); imageFactory.Resize(resizeLayer); imageFactory.Save(filePath); } result.success = true; result.imagePath = string.Format("/media/upload/{0}/{1}", guid, fileName); } else { result.success = false; result.message = "No images found"; } //jquery ajax file uploader expects html, it parses to json client side var response = new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(result)) }; response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/html"); return(response); }
public void TestMethod1() { var factory = new ImageProcessor.ImageFactory(); }