public ActionResult Thumb(string size, ThumbnailMethod mode, int q, string fn, WaterMarkingPosition?position) { Response.Cache.SetOmitVaryStar(true); var filePath = StringUtility.XBase64Decode(fn); var arrSize = size.ToLower().Split('x'); var dirRoot = AttachmentSvc.GetFullPath($@"thumb\{mode}-{size}-{position}"); var filePathAbs = Path.Combine(dirRoot, filePath); var dirPath = Path.GetDirectoryName(filePathAbs); if (string.IsNullOrEmpty(dirPath)) { return(HttpNotFound("-File Not Found-")); } if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } var fileExt = Path.GetExtension(filePathAbs); if (!System.IO.File.Exists(filePathAbs)) { var iThumb = new ImgThumbUtillity() { QualityLevel = q }; var filePathSrc = AttachmentSvc.GetFullPath(filePath); iThumb.MakeThumbnail(filePathSrc, filePathAbs, fileExt, StringUtility.ConvertToInt(arrSize[0]), StringUtility.ConvertToInt(arrSize[1]), mode, position, SysConfigRepository.WaterMarkingPath); } var fileContentType = AttachmentSvc.GetFileContentType(fileExt); return(File(filePathAbs, fileContentType)); }
public breinImage GetThumbnailImage(int width, int height, ThumbnailMethod method) { breinImage image; double imageRatio = (double)_image.Width / _image.Height; double thumbRatio = (double)width / height; if (method == ThumbnailMethod.Crop) { int imgWidth = width; int imgHeight = height; if (imageRatio < thumbRatio) { imgHeight = (_image.Height * width) / _image.Width; } else { imgWidth = (_image.Width * height) / _image.Height; } image = new breinImage(width, height); DrawScaledImage(image._image, _image, (width - imgWidth) / 2, (height - imgHeight) / 2, imgWidth, imgHeight); } else if (method == ThumbnailMethod.Pad) { // Rewritten to fix issue #1. Thanks to Cosmin! float hRatio = _image.Height / (float)height; float wRatio = _image.Width / (float)width; float newRatio = hRatio > wRatio ? hRatio : wRatio; int imgHeight = (int)(_image.Height / newRatio); int imgWidth = (int)(_image.Width / newRatio); image = new breinImage(width, height, _backgroundColor); DrawScaledImage(image._image, _image, (width - imgWidth) / 2, (height - imgHeight) / 2, imgWidth, imgHeight); } else // ThumbnailMethod.Fit { if (imageRatio < thumbRatio) { width = (_image.Width * height) / _image.Height; } else { height = (_image.Height * width) / _image.Width; } image = new breinImage(width, height); DrawScaledImage(image._image, _image, 0, 0, width, height); } return(image); }
// Constructor method public WebpageThumbnail(string data, int browserWidth, int browserHeight, int thumbnailWidth, int thumbnailHeight, ThumbnailMethod method) { this.Method = method; if (method == ThumbnailMethod.Url) { this.Url = data; } else if (method == ThumbnailMethod.Html) { this.Html = data; } this.BrowserWidth = browserWidth; this.BrowserHeight = browserHeight; this.Height = thumbnailHeight; this.Width = thumbnailWidth; }
public Thumbnail1(string data, int browserWidth, int browserHeight, int thumbnailWidth, int thumbnailHeight, ThumbnailMethod method) { this.Method = method; if (method == ThumbnailMethod.Url) { this.Url = data; } else if (method == ThumbnailMethod.Html) { this.Html = data; } this.BrowserWidth = 1089; // ;// browserWidth; this.BrowserHeight = 860; // browserHeight; this.Height = 2552; // thumbnailHeight; this.Width = 3302; // thumbnailWidth; }
public KalikoImage GetThumbnailImage(int width, int height, ThumbnailMethod method) { ScalingBase scaleEngine; switch (method) { case ThumbnailMethod.Fit: scaleEngine = new FitScaling(width, height); break; case ThumbnailMethod.Pad: scaleEngine = new PadScaling(width, height); break; default: scaleEngine = new CropScaling(width, height); break; } return(Scale(scaleEngine)); }
public KalikoImage GetThumbnailImage(int width, int height, ThumbnailMethod method) { ScalingBase scaleEngine; switch (method) { case ThumbnailMethod.Fit: scaleEngine = new FitScaling(width, height); break; case ThumbnailMethod.Pad: scaleEngine = new PadScaling(width, height); break; default: scaleEngine = new CropScaling(width, height); break; } return Scale(scaleEngine); }
public static string ThumbUrl(this UrlHelper urlHelper, string fn, string size, WaterMarkingPosition position, ThumbnailMethod mode = ThumbnailMethod.Crop, string defUrl = "") { if (string.IsNullOrEmpty(fn)) { return(defUrl); } fn = StringUtility.XBase64Encode(fn); var result = urlHelper.GenerateUrl("WaterThumbnail", "Thumb", "Utility", new { size, mode, fn, position }); return(GetImgSiteFile(result)); }
/// <summary> /// 缩略图的截图模式是:当原图宽高比按照缩略图时缩放 /// </summary> /// <param name="originalImagePath"></param> /// <param name="thumbnailPath"></param> /// <param name="extName"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="scale">Crop:取中间部分;Fit:按比例缩放,自动调整尺寸;Pad:按比例缩放,保持尺寸,不足部分填白</param> /// <param name="position">水印位置</param> /// <param name="waterMarkingPath">水印图片路劲</param> public void MakeThumbnail(string originalImagePath, string thumbnailPath, string extName, int width, int height, ThumbnailMethod scale = ThumbnailMethod.Fit, WaterMarkingPosition?position = null, string waterMarkingPath = "") { if (!File.Exists(originalImagePath)) { return; } var image = new KalikoImage(originalImagePath) { BackgroundColor = Color.White }; var format = GetImageFormat(extName); ScalingBase scalingBase = null; switch (scale) { case ThumbnailMethod.Crop: scalingBase = new CropScaling(width, height); break; case ThumbnailMethod.Fit: scalingBase = new FitScaling(width, height); break; case ThumbnailMethod.Pad: scalingBase = new PadScaling(width, height); break; default: scalingBase = new CropScaling(width, height); break; } var imageThumb = image.Scale(scalingBase); AddWaterMarking(position, waterMarkingPath, imageThumb); imageThumb.SaveImage(thumbnailPath, format); image.Dispose(); imageThumb.Dispose(); }
public breinImage GetThumbnailImage(int width, int height, ThumbnailMethod method) { breinImage image; double imageRatio = (double)_image.Width / _image.Height; double thumbRatio = (double)width / height; if(method == ThumbnailMethod.Crop ) { int imgWidth = width; int imgHeight = height; if(imageRatio < thumbRatio) { imgHeight = (_image.Height * width) / _image.Width; } else { imgWidth = (_image.Width * height) / _image.Height; } image = new breinImage(width, height); DrawScaledImage(image._image, _image, (width - imgWidth) / 2, (height - imgHeight) / 2, imgWidth, imgHeight); } else if(method == ThumbnailMethod.Pad) { // Rewritten to fix issue #1. Thanks to Cosmin! float hRatio = _image.Height / (float)height; float wRatio = _image.Width / (float)width; float newRatio = hRatio > wRatio ? hRatio : wRatio; int imgHeight = (int)(_image.Height / newRatio); int imgWidth = (int)(_image.Width / newRatio); image = new breinImage(width, height, _backgroundColor); DrawScaledImage(image._image, _image, (width - imgWidth) / 2, (height - imgHeight) / 2, imgWidth, imgHeight); } else { // ThumbnailMethod.Fit if(imageRatio < thumbRatio) { width = (_image.Width * height) / _image.Height; } else { height = (_image.Height * width) / _image.Width; } image = new breinImage(width, height); DrawScaledImage(image._image, _image, 0, 0, width, height); } return image; }