public GetPathToResizedImage ( string originalPath ) : string | ||
originalPath | string | |
리턴 | string |
protected override bool ProcessRequest(IRequestInfo info) { if (base.ProcessRequest(info)) { return(true); } if (!_useCache) { return(false); } var r = GetLocalPathWithoutQuery(info); if (r.EndsWith(".png") || r.EndsWith(".jpg")) { info.ContentType = r.EndsWith(".png") ? "image/png" : "image/jpeg"; r = r.Replace("thumbnail", ""); //if (r.Contains("thumb")) { if (File.Exists(r)) { info.ReplyWithImage(_cache.GetPathToResizedImage(r)); return(true); } } } return(false); }
/// <summary> /// This is designed to be easily unit testable by not taking actual HttpContext, but doing everything through this IRequestInfo object /// </summary> /// <param name="info"></param> public void MakeReply(IRequestInfo info) { if (info.LocalPathWithoutQuery.EndsWith("testconnection")) { info.WriteCompleteOutput("OK"); return; } var r = info.LocalPathWithoutQuery.Replace("/bloom/", ""); r = r.Replace("%3A", ":"); r = r.Replace("%20", " "); r = r.Replace("%27", "'"); if (r.EndsWith(".png") || r.EndsWith(".jpg")) { info.ContentType = r.EndsWith(".png") ? "image/png" : "image/jpeg"; r = r.Replace("thumbnail", ""); //if (r.Contains("thumb")) { if (File.Exists(r)) { info.ReplyWithImage(_cache.GetPathToResizedImage(r)); } else { Logger.WriteEvent("**ImageServer: File Missing: " + r); info.WriteError(404); } } } }
public void GetTinyImage_DoesNotChangeSize() { using (var cache = new LowResImageCache(new BookRenamedEvent()) { TargetDimension = 100 }) using (var file = MakeTempPNGImage(10,10)) { using (var img = Image.FromFile(cache.GetPathToResizedImage(file.Path))) { Assert.AreEqual(10, img.Width); } } }
public void GetWideImage_ReturnsShrunkImageWithCorrectProportions() { using (var cache = new LowResImageCache(new BookRenamedEvent()) { TargetDimension = 100 }) using (var file = MakeTempPNGImage(200,80)) { using(var img = Image.FromFile(cache.GetPathToResizedImage(file.Path))) { Assert.AreEqual(100, img.Width); Assert.AreEqual(40, img.Height); } } }
public void GetJPG_ReturnsShrunkJPG() { using (var cache = new LowResImageCache(new BookRenamedEvent()) { TargetDimension = 100 }) using (var file = MakeTempJPGImage(200, 80)) { var pathToResizedImage = cache.GetPathToResizedImage(file.Path); using (var img = Image.FromFile(pathToResizedImage)) { Assert.AreEqual(".jpg", Path.GetExtension(pathToResizedImage)); //TODO: why does this always report PNG format? Checks by hand of the file show it as jpg //Assert.AreEqual(ImageFormat.Jpeg.Guid, img.RawFormat.Guid); Assert.AreEqual(100, img.Width); Assert.AreEqual(40, img.Height); } } }