public static UrlBuilder FitMode(this UrlBuilder target, FitMode mode) { if (target == null) throw new ArgumentNullException(nameof(target)); target.QueryCollection.Add("mode", mode.ToString().ToLower()); return target; }
public static UrlBuilder FitMode(this UrlBuilder target, FitMode mode) { if (target == null) { throw new ArgumentNullException(nameof(target)); } if (!target.IsEmpty) { target.QueryCollection.Add("mode", mode.ToString().ToLower()); } return(target); }
public object ToImageflowDynamic(int?ioId) { return(new { io_id = ioId, gravity = Gravity?.ToImageflowDynamic(), fit_box = FitBox?.ToImageflowDynamic(), fit_mode = FitMode?.ToString().ToLowerInvariant(), min_canvas_width = MinCanvasWidth, min_canvas_height = MinCanvasWidth, opacity = Opacity, hints = Hints?.ToImageflowDynamic() }); }
/// <summary> /// Fits the specified image to the supplied max width and height. /// </summary> /// <param name="image">The image.</param> /// <param name="maxWidth">Width of the max.</param> /// <param name="maxHeight">Height of the max.</param> /// <param name="fitMode">The fit mode.</param> /// <param name="scaleMode">The scale mode.</param> /// <param name="alignMode">The align mode.</param> /// <param name="format">The format.</param> /// <param name="quality">The quality.</param> /// <param name="colors">The colors.</param> /// <param name="bgColor">Color of the background.</param> /// <returns></returns> public static IFilteredImage Fit(this IFilteredImage image, int maxWidth, int maxHeight, FitMode fitMode = FitMode.Pad, ScaleMode scaleMode = ScaleMode.Down, AlignMode alignMode = AlignMode.MiddleCenter, ImageFormat format = ImageFormat.Auto, int quality = 90, int colors = 256, string bgColor = "") { image.Filters.Add("w", maxWidth); image.Filters.Add("h", maxHeight); if (fitMode != FitMode.Pad) { image.Filters.Add("mode", fitMode.ToString().ToLower()); } if (scaleMode != ScaleMode.Down) { image.Filters.Add("scale", scaleMode.ToString().ToLower()); } if (alignMode != AlignMode.MiddleCenter) { image.Filters.Add("anchor", alignMode.ToString().ToLower()); } if (format != ImageFormat.Auto) { image.Filters.Add("format", format.ToString().ToLower()); } if (quality != 90) { image.Filters.Add("quality", Math.Min(100, Math.Max(0, quality))); } if (colors != 256) { image.Filters.Add("colors", Math.Min(256, Math.Max(2, quality))); } if (!string.IsNullOrEmpty(bgColor)) { image.Filters.Add("bgcolor", bgColor); } return(image); }
public void SetBitmap() { double SX = 1.0; double SY = 1.0; if ((int)WindImage.Fitting == 0) { SX = WindImage.BitmapImage.Width / Width; SY = WindImage.BitmapImage.Height / Height; double TZ = 1.0; if (SY > SX) { TZ = SY; } else { TZ = SX; } SX = SX / TZ; SY = SY / TZ; } FillSpace = (FillMode)(int)WindImage.Fitting; Alignment = (AlignMode)WindImage.Alignment; Fitting = (FitMode)WindImage.Fitting; string FitAlignment = Alignment.ToString() + " " + Fitting.ToString(); if (Fitting == FitMode.none) { FitAlignment = "none"; } if (WindImage.IsEmbedded) { Location = "data:image/png;base64," + Convert.ToBase64String(WindImage.ImageByteArray); } else { Location = "file:" + System.Text.Encoding.Default.GetString(WindImage.BitmapImage.GetPropertyItem(0).Value); } FillMode ModeContent = (FillMode)(ContentModes[(int)WindImage.Fitting]); StringBuilder StyleAssembly = new StringBuilder(); StyleAssembly.Append("<defs>" + Environment.NewLine); StyleAssembly.Append("<pattern id=\"grad" + Index + "\" width=\"" + SX + "\" height=\"" + SY + "\" " + Environment.NewLine); StyleAssembly.Append("patternUnits=\"objectBoundingBox\" patternContentUnits =\"" + ModeContent.ToString() + "\" " + Environment.NewLine); StyleAssembly.Append("viewBox=\"0 0 1 1\" " + Environment.NewLine); StyleAssembly.Append("preserveAspectRatio=\"" + FitAlignment + "\" " + Environment.NewLine); StyleAssembly.Append("patternTransform=\" rotate(" + WindImage.Angle + ")\" >" + Environment.NewLine); StyleAssembly.Append("<image width=\"1\" height=\"1\" preserveAspectRatio=\"" + FitAlignment + "\" href =\"" + Location + "\" />" + Environment.NewLine); StyleAssembly.Append("</pattern>" + Environment.NewLine); StyleAssembly.Append("</defs>" + Environment.NewLine); Style = StyleAssembly.ToString(); Value = "fill=\"url(#grad" + Index + ")\"" + Environment.NewLine; }
public Dictionary<string, string> getFileResized(string photoName, string path, int width, int height, FitMode mode) { Dictionary<string, string> returnItem = new Dictionary<string, string>(); if (string.IsNullOrWhiteSpace(photoName) || string.IsNullOrWhiteSpace(path)) { return null; } var fileProperty = getExtenstionWithFileExistControl(path, photoName); if (fileProperty.Item1) { string resultExtention = fileProperty.Item2; string filePath = fileProperty.Item3; string withoutCommaCoordinate = width.ToString() + height.ToString(); string filePathWithCoordiante = Server.MapPath("~/" + "Download/item/" + path + "/" + withoutCommaCoordinate + mode.ToString() + "_" + photoName); if (System.IO.File.Exists(filePathWithCoordiante)) { returnItem.Add(filePathWithCoordiante, resultExtention); return returnItem; } else { var settings = new ResizeSettings(); settings.Width = width; settings.Height = height; settings.Mode = mode; settings.Quality = 100; ImageBuilder.Current.Build(filePath, filePathWithCoordiante, settings); returnItem.Add(filePathWithCoordiante, resultExtention); return returnItem; } } return null; }
/// <summary> /// Fits the specified image to the supplied max width and height. /// </summary> /// <param name="image">The image.</param> /// <param name="maxWidth">Width of the max.</param> /// <param name="maxHeight">Height of the max.</param> /// <param name="fitMode">The fit mode.</param> /// <param name="scaleMode">The scale mode.</param> /// <param name="alignMode">The align mode.</param> /// <param name="format">The format.</param> /// <param name="quality">The quality.</param> /// <param name="colors">The colors.</param> /// <param name="bgColor">Color of the background.</param> /// <returns></returns> public static IFilteredImage Fit(this IFilteredImage image, int maxWidth, int maxHeight, FitMode fitMode = FitMode.Pad, ScaleMode scaleMode = ScaleMode.Down, AlignMode alignMode = AlignMode.MiddleCenter, ImageFormat format = ImageFormat.Auto, int quality = 90, int colors = 256, string bgColor = "") { image.Filters.Add("w", maxWidth); image.Filters.Add("h", maxHeight); if(fitMode != FitMode.Pad) image.Filters.Add("mode", fitMode.ToString().ToLower()); if(scaleMode != ScaleMode.Down) image.Filters.Add("scale", scaleMode.ToString().ToLower()); if(alignMode != AlignMode.MiddleCenter) image.Filters.Add("anchor", alignMode.ToString().ToLower()); if(format != ImageFormat.Auto) image.Filters.Add("format", format.ToString().ToLower()); if(quality != 90) image.Filters.Add("quality", Math.Min(100, Math.Max(0, quality))); if (colors != 256) image.Filters.Add("colors", Math.Min(256, Math.Max(2, quality))); if (!string.IsNullOrEmpty(bgColor)) image.Filters.Add("bgcolor", bgColor); return image; }