/// <summary> /// /// </summary> /// <param name="man"></param> /// <param name="file"></param> /// <param name="type"></param> /// <param name="info"></param> /// <returns></returns> public override bool OnCustomInfo(ManagerEngine man, IFile file, string type, Hashtable info) { string ext = PathUtils.GetExtension(file.Name).ToLower(); info["thumbnail"] = false; switch (ext) { case "gif": case "jpeg": case "jpg": case "png": MediaInfo imageSize = new MediaInfo(file.AbsolutePath); ManagerConfig config = file.Config; int thumbWidth, thumbHeight; double scale; // Constrain proportions scale = Math.Min(config.GetInt("thumbnail.width", 90) / (double)imageSize.Width, config.GetInt("thumbnail.height", 90) / (double)imageSize.Height); if (config.Get("thumbnail.scale_mode", "percentage") == "percentage") { thumbWidth = scale > 1 ? imageSize.Width : (int)Math.Floor(imageSize.Width * scale); thumbHeight = scale > 1 ? imageSize.Height : (int)Math.Floor(imageSize.Height * scale); } else { thumbWidth = config.GetInt("thumbnail.width", 90); thumbHeight = config.GetInt("thumbnail.height", 90); } info["width"] = imageSize.Width; info["height"] = imageSize.Height; info["editable"] = true; info["twidth"] = thumbWidth; info["theight"] = thumbHeight; info["thumbnail"] = true; // Get thumbnail URL if (type == "insert") { IFile thumbFile = man.GetFile(file.Parent + "/" + config.Get("thumbnail.folder", "mcith") + "/" + config.Get("thumbnail.prefix", "mcith") + file.Name); if (thumbFile.Exists) { info["thumbnail_url"] = man.ConvertPathToURI(thumbFile.AbsolutePath); } } break; } return(true); }
private IFile MakeThumb(ManagerEngine man, IFile file) { ManagerConfig config = file.Config; IFile thumbFile; int thumbWidth, thumbHeight; int configWidth, configHeight; double scale; MediaInfo thumbSize = new MediaInfo(); // Is not enabled if (!config.GetBool("thumbnail.enabled", true)) { return(file); } // Setup thumbnail path IFile thumbDir = man.GetFile(file.Parent, config.Get("thumbnail.folder", "mcith")); if (!thumbDir.Exists) { thumbDir.MkDir(); } configWidth = config.GetInt("thumbnail.width", 90); configHeight = config.GetInt("thumbnail.height", 90); // Make thumbnail thumbFile = man.GetFile(thumbDir.AbsolutePath, config.Get("thumbnail.prefix", "mcith") + file.Name); MediaInfo imageSize = new MediaInfo(file.AbsolutePath); // Need to scale? if (imageSize.Width < configWidth && imageSize.Height < configHeight) { return(file); } // To large if (imageSize.Width > config.GetInt("thumbnail.max_width", 65535) || imageSize.Height > config.GetInt("thumbnail.max_height", 65535)) { return(file); } // Constrain proportions scale = Math.Min(configWidth / (double)imageSize.Width, configHeight / (double)imageSize.Height); if (config.Get("thumbnail.scale_mode", "percentage") == "percentage") { thumbWidth = scale > 1 ? imageSize.Width : (int)Math.Floor(imageSize.Width * scale); thumbHeight = scale > 1 ? imageSize.Height : (int)Math.Floor(imageSize.Height * scale); } else { thumbWidth = config.GetInt("thumbnail.width", 90); thumbHeight = config.GetInt("thumbnail.height", 90); } if (thumbFile.Exists) { thumbSize = new MediaInfo(thumbFile.AbsolutePath); } if (!thumbFile.Exists || thumbSize.Width != thumbWidth || thumbSize.Height != thumbHeight || file.LastModified != thumbFile.LastModified) { ImageUtils.MakeThumbnail(file.AbsolutePath, thumbFile.AbsolutePath, thumbWidth, thumbHeight, file.LastModified, config.GetInt("thumbnail.jpeg_quality", 75)); } return(thumbFile); }