static void Thumb(Image img) { var file = UploadService.GetFileInfo(img.Id); string filename_without_extension = Path.GetFileNameWithoutExtension(file.Name); string thumb = filename_without_extension + DownSite.Constants.Seperator + "thumb.jpg"; var thumb_file = FileCache.GetFile(thumb); if (thumb_file != null) { return; } thumb_file = new FileInfo(Path.Combine(FileCache.GetCacheDir().FullName, thumb)); var mimetypes = new string[] { MimeTypes.ImageJpg, MimeTypes.ImagePng, MimeTypes.ImageGif }; if (!mimetypes.Contains(img.MimeType)) { VideoThumbnailer.MakeThumbnail(file.FullName, thumb_file.FullName); } else { using (var fs = file.OpenRead()) { using (Bitmap bmp = new Bitmap(fs)) { using (var thumb2 = bmp.GetThumbnailImage(80, 80, null, IntPtr.Zero)) { ImageService.SaveJpeg(thumb2, thumb_file.FullName); } } } } }
public object Get(ImageRequest request) { var img = Image.Load(request.Id); if (img != null) { bool thumb3 = request.Param.Contains("thumb"); if (!thumb3) { var res = ResizeHelper(request, img.Item1, ResizeHeights, x => "0x" + x); if (res != null) { return(res); } res = ResizeHelper(request, img.Item1, ResizeWidths, x => x + "x0"); if (res != null) { return(res); } } if (thumb3) { string filename_without_extension = Path.GetFileNameWithoutExtension(img.Item2.Name); string thumb = filename_without_extension + DownSite.Constants.Seperator + "thumb.jpg"; var thumb_file = FileCache.GetFile(thumb); if (thumb_file != null) { return(new HttpResult(thumb_file, MimeTypes.ImageJpg) { }); } thumb_file = new FileInfo(Path.Combine(FileCache.GetCacheDir().FullName, thumb)); var mimetypes = new string[] { MimeTypes.ImageJpg, MimeTypes.ImagePng, MimeTypes.ImageGif }; if (!mimetypes.Contains(img.Item1.MimeType)) { if (VideoThumbnailer.MakeThumbnail(img.Item2.FullName, thumb_file.FullName)) { return(new HttpResult(thumb_file, MimeTypes.ImageJpg) { }); } else { return(new HttpResult(System.Net.HttpStatusCode.NotFound, string.Format("No thumbnails for type {0}.", img.Item1.MimeType))); } } else { using (var fs = img.Item2.OpenRead()) { using (Bitmap bmp = new Bitmap(fs)) { using (var thumb2 = bmp.GetThumbnailImage(80, 80, null, IntPtr.Zero)) { SaveJpeg(thumb2, thumb_file.FullName); return(new HttpResult(thumb_file, MimeTypes.ImageJpg) { }); } } } } } else { var res = new HttpResult(img.Item2, string.IsNullOrWhiteSpace(img.Item1.MimeType) ? MimeTypes.ImageJpg : img.Item1.MimeType) { }; if (img.Item1.MimeType == "application/octet-stream") { res.Options.Add("Content-Disposition", "attachment; filename=\"" + img.Item1.FileName + "\""); } return(res); } } return(new HttpResult(System.Net.HttpStatusCode.NotFound, "No image with that ID.")); }
static VideoProbe() { avprobe = VideoThumbnailer.CheckProgram("avprobe"); ffprobe = VideoThumbnailer.CheckProgram("ffprobe"); }