private static string SpecialEffectImage(IMatrixFilter effectFilter, string imageFilePath, bool isActualSize) { var specialEffectImageFile = Util.TempPath.GetPath("fullsize_specialeffect"); using (var imageFactory = new ImageFactory()) { var image = imageFactory .Load(imageFilePath) .Image; var ratio = (float)image.Width / image.Height; if (isActualSize) { image = imageFactory .Resize(new Size((int)(768 * ratio), 768)) .Filter(effectFilter) .Image; } else { image = imageFactory .Resize(new Size((int)(300 * ratio), 300)) .Filter(effectFilter) .Image; } image.Save(specialEffectImageFile); } return specialEffectImageFile; }
private static string BlurImage(string imageFilePath, int degree) { if (degree == 0) { return imageFilePath; } var resizeImageFile = Util.TempPath.GetPath("fullsize_resize"); using (var imageFactory = new ImageFactory()) { var image = imageFactory .Load(imageFilePath) .Image; var ratio = (float)image.Width / image.Height; var targetHeight = Math.Round(MaxThumbnailHeight - (MaxThumbnailHeight - MinThumbnailHeight) / 100f * degree); var targetWidth = Math.Round(targetHeight * ratio); image = imageFactory .Resize(new Size((int)targetWidth, (int)targetHeight)) .Image; image.Save(resizeImageFile); } var blurImageFile = Util.TempPath.GetPath("fullsize_blur"); using (var imageFactory = new ImageFactory()) { var image = imageFactory .Load(resizeImageFile) .GaussianBlur(5) .Image; image.Save(blurImageFile); } return blurImageFile; }
public static string GetThumbnailFromFullSizeImg(string filename) { var thumbnailPath = StoragePath.GetPath("thumbnail-" + DateTime.Now.GetHashCode() + "-" + Guid.NewGuid().ToString().Substring(0, 7)); using (var imageFactory = new ImageFactory()) { var image = imageFactory .Load(filename) .Image; var ratio = (float) image.Width / image.Height; image = imageFactory .Resize(new Size((int)(ThumbnailHeight * ratio), ThumbnailHeight)) .Image; image.Save(thumbnailPath); } return thumbnailPath; }
public IActionResult Download([FromRoute] string filepath) { //TODO authorize if (string.IsNullOrWhiteSpace(filepath)) return DoPageNotFoundResponse(); if (!filepath.StartsWith("/")) filepath = "/" + filepath; filepath = filepath.ToLowerInvariant(); DbFileRepository fsRepository = new DbFileRepository(); var file = fsRepository.Find(filepath); if (file == null) return DoPageNotFoundResponse(); //check for modification string headerModifiedSince = Request.Headers["If-Modified-Since"]; if (headerModifiedSince != null) { DateTime isModifiedSince; if (DateTime.TryParse(headerModifiedSince, out isModifiedSince)) { if (isModifiedSince <= file.LastModificationDate) { Response.StatusCode = 304; return new EmptyResult(); } } } HttpContext.Response.Headers.Add("last-modified", file.LastModificationDate.ToString()); string mimeType; var extension = Path.GetExtension(filepath).ToLowerInvariant(); new FileExtensionContentTypeProvider().Mappings.TryGetValue(extension, out mimeType); IDictionary<string, StringValues> queryCollection = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(HttpContext.Request.QueryString.ToString()); string action = queryCollection.Keys.Any(x => x == "action") ? ((string)queryCollection["action"]).ToLowerInvariant() : ""; string requestedMode = queryCollection.Keys.Any(x => x == "mode") ? ((string)queryCollection["mode"]).ToLowerInvariant() : ""; string width = queryCollection.Keys.Any(x => x == "width") ? ((string)queryCollection["width"]).ToLowerInvariant() : ""; string height = queryCollection.Keys.Any(x => x == "height") ? ((string)queryCollection["height"]).ToLowerInvariant() : ""; bool isImage = extension == ".jpg" || extension == ".jpeg" || extension == ".png" || extension == ".gif"; if (isImage && (!string.IsNullOrWhiteSpace(action) || !string.IsNullOrWhiteSpace(requestedMode) || !string.IsNullOrWhiteSpace(width) || !string.IsNullOrWhiteSpace(height))) { var fileContent = file.GetBytes(); using (ImageFactory imageFactory = new ImageFactory()) { using (Stream inStream = new MemoryStream(fileContent)) { MemoryStream outStream = new MemoryStream(); imageFactory.Load(inStream); //sets background System.Drawing.Color backgroundColor = System.Drawing.Color.White; switch (imageFactory.CurrentImageFormat.MimeType) { case "image/gif": case "image/png": backgroundColor = System.Drawing.Color.Transparent; break; default: break; } switch (action) { default: case "resize": { ResizeMode mode; switch (requestedMode) { case "boxpad": mode = ResizeMode.BoxPad; break; case "crop": mode = ResizeMode.Crop; break; case "min": mode = ResizeMode.Min; break; case "max": mode = ResizeMode.Max; break; case "stretch": mode = ResizeMode.Stretch; break; default: mode = ResizeMode.Pad; break; } Size size = ParseSize(queryCollection); ResizeLayer rl = new ResizeLayer(size, mode); imageFactory.Resize(rl).BackgroundColor(backgroundColor).Save(outStream); } break; } outStream.Seek(0, SeekOrigin.Begin); return File(outStream, mimeType); } } } return File(file.GetBytes(), mimeType); }
private string SaveLargeImage(byte[] bytes, string fileName) { using (MemoryStream inStream = new MemoryStream(bytes)) { using (MemoryStream outStream = new MemoryStream()) { using (ImageFactory imageFactory = new ImageFactory()) { // Load, resize, set the format and quality and save an image. imageFactory.Load(inStream); int width = imageFactory.Image.Size.Width; int height = imageFactory.Image.Size.Height; if (width > 1600) { int newHeight = (int)((1600 / (double)width) * height); imageFactory.Resize(new Size(1600, newHeight)); imageFactory.Format(ImageFormat.Jpeg); imageFactory.Quality(80); imageFactory.Save(outStream); } else if (height > 1600) { int newWidth = (int)((1600 / (double)height) * width); imageFactory.Resize(new Size(newWidth, 1600)); imageFactory.Format(ImageFormat.Jpeg); imageFactory.Quality(80); imageFactory.Save(outStream); } else { imageFactory.Save(outStream); } } outStream.Position = 0; var resizedResult = this._fileStorage.UploadFile(outStream, fileName, "products/"); return resizedResult.Uri.ToString(); } } }
private string SaveThumbnail(byte[] bytes, string fileName) { using (MemoryStream inStream = new MemoryStream(bytes)) { using (MemoryStream outStream = new MemoryStream()) { using (ImageFactory imageFactory = new ImageFactory()) { // Load, resize, set the format and quality and save an image. imageFactory.Load(inStream); imageFactory.Resize(new Size(200, 0)); imageFactory.Format(ImageFormat.Jpeg); imageFactory.Quality(80); imageFactory.Save(outStream); } outStream.Position = 0; var thumbnailResult = this._fileStorage.UploadFile(outStream, "thumb-" + fileName, "products/"); return thumbnailResult.Uri.ToString(); } } }
/// <summary> /// Method to resize, convert and save the image. /// </summary> /// <param name="strImage"></param> /// <param name="maxHeight">resize width.</param> private static byte[] ResizeImage(MemoryStream strImage, int maxHeight) { var image = new Bitmap(strImage); // Get the image's original width and height var originalWidth = image.Width; var originalHeight = image.Height; // To preserve the aspect ratio var ratio = (float)maxHeight / (float)originalHeight; // New width and height based on aspect ratio var newWidth = (int)(originalWidth * ratio); var newHeight = (int)(originalHeight * ratio); var mem = new MemoryStream(); using (var img = new ImageFactory()) { img.Load(strImage); img.Resize(new Size(newWidth, newHeight)).Save(mem); } return mem.ToArray(); }
private string CreateThumbnailImage(string fileName, string thumbFileName) { string tempPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), thumbFileName); var imageFactory = new ImageFactory ().Load(fileName); var size = (imageFactory.Image.Width > imageFactory.Image.Height) ? new Size(150, 0) : new Size(0, 150); ImageFactory resized = imageFactory.Resize(size); resized.Save(tempPath); return tempPath; }
private void goGenerateProcessesFriendship() { int artOfficial = 0; foreach (var theProcess in Process.GetProcesses()) { if (theProcess.MainWindowTitle != "" && theProcess.MainWindowTitle != "Space") { artOfficial++; } } if (artOfficial != currentCountProc) { spaceForProcesses.Controls.Clear(); int procCount = 0; foreach (var theProcess in Process.GetProcesses()) { if (procCount != 0 && procCount != 4) { if ((theProcess.MainWindowTitle != "" && theProcess.Modules[0].FileName != "ProjectSnowshoes.exe") && theProcess.MainWindowHandle != null) { foreach (var h in getHandles(theProcess)) { if (IsWindowVisible(h)) { PictureBox hmGreatJobFantasticAmazing = new PictureBox(); StringBuilder sb = new StringBuilder(GetWindowTextLength(h) + 1); GetWindowText(h, sb, sb.Capacity); hmGreatJobFantasticAmazing.Margin = new Padding(6, 0, 6, 0); hmGreatJobFantasticAmazing.Visible = true; hmGreatJobFantasticAmazing.SizeMode = PictureBoxSizeMode.CenterImage; hmGreatJobFantasticAmazing.BackgroundImageLayout = ImageLayout.Zoom; Icon.ExtractAssociatedIcon(theProcess.Modules[0].FileName).ToBitmap().Save(@"C:\ProjectSnowshoes\temptaskico.png"); ImageFactory grayify = new ImageFactory(); grayify.Load(@"C:\ProjectSnowshoes\temptaskico.png"); Size sizeeeee = new System.Drawing.Size(); sizeeeee.Height = 20; sizeeeee.Width = 20; ImageProcessor.Imaging.ResizeLayer reLay = new ImageProcessor.Imaging.ResizeLayer(sizeeeee); grayify.Resize(reLay); hmGreatJobFantasticAmazing.Image = grayify.Image; hmGreatJobFantasticAmazing.Click += (sender, args) => { ShowWindow(theProcess.MainWindowHandle, 5); ShowWindow(theProcess.MainWindowHandle, 9); }; hmGreatJobFantasticAmazing.MouseHover += (sender, args) => { Properties.Settings.Default.stayHere = true; Properties.Settings.Default.Save(); int recordNao = hmGreatJobFantasticAmazing.Left; hmGreatJobFantasticAmazing.Image.Save(@"C:\ProjectSnowshoes\TheyNeedToKeepOriginalAlbums.png"); Size sizeeeeeA = new System.Drawing.Size(); sizeeeeeA.Height = 100; sizeeeeeA.Width = 100; ImageProcessor.Imaging.ResizeLayer reLayA = new ImageProcessor.Imaging.ResizeLayer(sizeeeeeA); ImageProcessor.Imaging.GaussianLayer gauLay = new ImageProcessor.Imaging.GaussianLayer(); gauLay.Sigma = 2; gauLay.Threshold = 10; gauLay.Size = 20; ImageFactory backify = new ImageFactory(); backify.Load(@"C:\ProjectSnowshoes\TheyNeedToKeepOriginalAlbums.png"); backify.Brightness(-30); backify.Resize(reLayA); backify.GaussianBlur(gauLay); ImageProcessor.Imaging.CropLayer notAsLongAsOriginalName = new ImageProcessor.Imaging.CropLayer(90, 0, 0, 0, ImageProcessor.Imaging.CropMode.Percentage); backify.Crop(new Rectangle(25, (100 - this.Height) / 2, 50, this.Height)); hmGreatJobFantasticAmazing.BackgroundImage = backify.Image; grayify.Save(@"C:\ProjectSnowshoes\TheyStillNeedToKeepOriginalAlbums.png"); ImageFactory grayifyA = new ImageFactory(); grayifyA.Load(@"C:\ProjectSnowshoes\TheyStillNeedToKeepOriginalAlbums.png"); grayifyA.Saturation(44); grayifyA.Brightness(42); hmGreatJobFantasticAmazing.Image = grayifyA.Image; // Yeahhhhhhhhh I'm going to have to do this another way // panel1.Controls.Add(areYouSeriouslyStillDoingThisLetItGo); // Oh // I can just make another form to draw over and go have turnips with parameters // Also credits to Microsoft Word's "Sentence Case" option as this came out in all caps originally // Measuring string turnt-up-edness was guided by an answer on Stack Overflow by Tom Anderson. String keepThisShortWeNeedToOptimize = sb.ToString().Replace("&", "&&"); Graphics heyGuessWhatGraphicsYeahThatsRight = Graphics.FromImage(new Bitmap(1, 1)); SizeF sure = heyGuessWhatGraphicsYeahThatsRight.MeasureString(keepThisShortWeNeedToOptimize, new System.Drawing.Font(Properties.Settings.Default.fontsOfScience[Properties.Settings.Default.whoIsThisCrazyDoge], 14, FontStyle.Regular, GraphicsUnit.Point)); Size sureAgain = sure.ToSize(); int recordThatJim; if (sureAgain.Width >= 300) { recordThatJim = sureAgain.Width + 10; } else { recordThatJim = 300; } CanWeMakeAHoverFormLikeThisIsThisLegal notAsLongInstanceName = new CanWeMakeAHoverFormLikeThisIsThisLegal(recordNao + 150, this.Height, recordThatJim, keepThisShortWeNeedToOptimize); notAsLongInstanceName.Show(); notAsLongInstanceName.BringToFront(); //hmGreatJobFantasticAmazing.BringToFront(); //panel1.Controls.Add(hmGreatJobFantasticAmazing); //hmGreatJobFantasticAmazing.Top = this.Top - 40; //hmGreatJobFantasticAmazing.Left = recordNao + 150; //hmGreatJobFantasticAmazing.BringToFront(); //hmGreatJobFantasticAmazing.Invalidate(); /*hmGreatJobFantasticAmazing.Height = 100; hmGreatJobFantasticAmazing.Width = 100;*/ }; hmGreatJobFantasticAmazing.MouseLeave += (sender, args) => { /*hmGreatJobFantasticAmazing.ImageAlign = ContentAlignment.MiddleCenter; hmGreatJobFantasticAmazing.AutoEllipsis = false; hmGreatJobFantasticAmazing.Width = 40; hmGreatJobFantasticAmazing.BackColor = Color.Transparent; //hmGreatJobFantasticAmazing.Font = new System.Drawing.Font(Properties.Settings.Default.fontsOfScience[Properties.Settings.Default.whoIsThisCrazyDoge], 14, FontStyle.Regular); //hmGreatJobFantasticAmazing.ForeColor = Color.White; hmGreatJobFantasticAmazing.TextAlign = ContentAlignment.MiddleLeft; hmGreatJobFantasticAmazing.Text = "";*/ try { Application.OpenForms["CanWeMakeAHoverFormLikeThisIsThisLegal"].Close(); } catch (Exception exTurnip) { } hmGreatJobFantasticAmazing.BackgroundImage = null; hmGreatJobFantasticAmazing.Invalidate(); Properties.Settings.Default.stayHere = false; Properties.Settings.Default.Save(); hmGreatJobFantasticAmazing.Image = grayify.Image; }; //openFileToolTip.SetToolTip(hmGreatJobFantasticAmazing, theProcess.MainWindowTitle); //hmGreatJobFantasticAmazing.BackgroundImage = Icon.ExtractAssociatedIcon(theProcess.Modules[0].FileName).ToBitmap(); hmGreatJobFantasticAmazing.Height = this.Height; hmGreatJobFantasticAmazing.Width = 50; spaceForProcesses.Controls.Add(hmGreatJobFantasticAmazing); } } } } procCount++; } } currentCountProc = artOfficial; }
public static void TaskMain(string[] args) { if (args == null || args.Length != 4) { throw new Exception("Usage: ImageBlur.exe --Task <blobpath> <storageAccountName> <storageAccountKey>"); } string blobName = args[1]; string storageAccountName = args[2]; string storageAccountKey = args[3]; string workingDirectory = Environment.GetEnvironmentVariable("AZ_BATCH_TASK_WORKING_DIR"); int numberToBlur = 3; Console.WriteLine(); Console.WriteLine(" blobName: <{0}>", blobName); Console.WriteLine(" storageAccountName: <{0}>", storageAccountName); Console.WriteLine(" number to blur: <{0}>", numberToBlur); Console.WriteLine(); // get source image from cloud blob var storageCred = new StorageCredentials(storageAccountName, storageAccountKey); CloudBlockBlob blob = new CloudBlockBlob(new Uri(blobName), storageCred); using (MemoryStream inStream = new MemoryStream()) { blob.DownloadToStream(inStream); Image img = Image.FromStream(inStream); int imgWidth = img.Width; int imgHeight = img.Height; Size size = new Size(imgWidth, imgHeight); ISupportedImageFormat format = new JpegFormat { Quality = 70 }; // Print image properties to stdout Console.WriteLine(" Image Properties:"); Console.WriteLine(" Format: {0}", FormatUtilities.GetFormat(inStream)); Console.WriteLine(" Size: {0}", size.ToString()); Console.WriteLine(); for (var i = 0; i < numberToBlur; i++) { using (ImageFactory imageFactory = new ImageFactory(preserveExifData: true)) { int blurIndex = (i * 5) + 10; imageFactory.Load(inStream); imageFactory.Resize(size) .Format(format) .GaussianBlur(blurIndex) .Save(workingDirectory + "/resultimage" + i + ".Jpeg"); //.Save(@"C:/Users/jiata/Desktop/imageblur/results/resultimage" + i + ".Jpeg"); } } } // TODO - not working for (var i = 0; i < numberToBlur; i++) { blob.UploadFromFile(workingDirectory + "/resultimage" + i + ".Jpeg", FileMode.Open); } Environment.Exit(1); }
private String ProcessImage(String fileName) { String newPath = ""; using (ImageFactory imageFactory = new ImageFactory(preserveExifData: true)) { imageFactory.Load(fileName); int width = imageFactory.Image.Width; int height = imageFactory.Image.Height; int newWidth = 1400; int newHeight = newWidth / width * height; newPath = ".//" + Path.GetFileNameWithoutExtension(fileName) + "_new" + Path.GetExtension(fileName); imageFactory.Resize(new Size(newWidth, newHeight)).Brightness(20).Contrast(100).Contrast(50).Save(newPath); } using (var engine = new TesseractEngine(@"./tessdata", "mcr", EngineMode.Default)) { using (var img = Pix.LoadFromFile(newPath)) { using (var page = engine.Process(img)) { var text = page.GetText(); Console.WriteLine(text); //Remove extra characters char[] arr = text.ToCharArray(); int start = 0, flag = 0; for (start = arr.Length - 1; start >= 0; start--) { if (Char.IsDigit(arr[start])) flag = 1; if (flag == 1 && arr[start] == '\n') break; } if (start < 0) start = 0; char[] newArr = new char[arr.Length + 1]; int j = 0; for (int i = start; i < arr.Length; i++) { if (Char.IsDigit(arr[i])) newArr[j++] = arr[i]; } newArr[j] = '\0'; //Return result File.Delete(newPath); return new String(newArr); } } } }