public byte[] Get(string relativeFilePath, int width, int height, ImageMod imageMod, string hexBackgroundColour, AnchorPosition?anchor, OutputFormat outputFormat) { using (var bitmap = Get(relativeFilePath, width, height, imageMod, hexBackgroundColour, anchor)) { return(bitmap.GetBytes(outputFormat)); } }
public byte[] Get(string relativeFilePath, int width, int height, ImageMod imageMod, string hexBackgroundColour, AnchorPosition? anchor, OutputFormat outputFormat) { using (var bitmap = Get(relativeFilePath, width, height, imageMod, hexBackgroundColour, anchor)) { return bitmap.GetBytes(outputFormat); } }
public Bitmap Get(string relativeFilePath, int width, int height, ImageMod imageMod, string hexBackgroundColour, AnchorPosition? anchor) { using (var image = (relativeFilePath == "Default" ? getDefault(width, height) : loadImage(relativeFilePath) ?? getDefault(width, height))) { return ResizeUtility.Get(image, width, height, imageMod, hexBackgroundColour, anchor); } }
public static Bitmap Get(Image image, int width, int height, ImageMod imageMod, string hexBackgroundColour, AnchorPosition? anchor) { switch (imageMod) { case ImageMod.Scale: return Scale(image, width, height, hexBackgroundColour); case ImageMod.Crop: return Crop(image, width, height, anchor ?? AnchorPosition.Center); default: return Scale(image, width, height, hexBackgroundColour); } }
public Bitmap Get(string relativeFilePath, int width, int height, ImageMod imageMod, string hexBackgroundColour, AnchorPosition? anchor) { using (var image = (relativeFilePath == "Default" ? getDefault(width, height) : loadImage(relativeFilePath) ?? getDefault(width, height))) { switch (imageMod) { case ImageMod.Scale: return scale(image, width, height, hexBackgroundColour); case ImageMod.Crop: return crop(image, width, height, anchor ?? AnchorPosition.Center); default: return scale(image, width, height, hexBackgroundColour); } } }
public byte[] GetCached(string relativeFilePath, int width, int height, ImageMod imageMod, string hexBackgroundColour, AnchorPosition?anchor, OutputFormat outputFormat) { var key = string.Format("ImageManager-{0}-{1}-{2}-{3}-{4}", relativeFilePath, width, height, imageMod, outputFormat); if (Context.Cache[key] == null) { var image = Get(relativeFilePath, width, height, imageMod, hexBackgroundColour, anchor, outputFormat); if (image == null) { throw new FileNotFoundException("The image requested does not exist."); } Context.Cache.Insert(key, image, null, Cache.NoAbsoluteExpiration, Configs.CacheExpiration); } return((byte[])Context.Cache[key]); }
public Bitmap Get(string relativeFilePath, int width, int height, ImageMod imageMod, string hexBackgroundColour, AnchorPosition?anchor) { using (var image = (relativeFilePath == "Default" ? getDefault(width, height) : loadImage(relativeFilePath) ?? getDefault(width, height))) { switch (imageMod) { case ImageMod.Scale: return(scale(image, width, height, hexBackgroundColour)); case ImageMod.Crop: return(crop(image, width, height, anchor ?? AnchorPosition.Center)); default: return(scale(image, width, height, hexBackgroundColour)); } } }
public byte[] GetCached(string relativeFilePath, int width, int height, ImageMod imageMod, string hexBackgroundColour, AnchorPosition? anchor, OutputFormat outputFormat) { var key = string.Format("ImageManager-{0}-{1}-{2}-{3}-{4}", relativeFilePath, width, height, imageMod, outputFormat); if (Context.Cache[key] == null) { var image = Get(relativeFilePath, width, height, imageMod, hexBackgroundColour, anchor, outputFormat); if (image == null) throw new FileNotFoundException("The image requested does not exist."); Context.Cache.Insert(key, image, null, Cache.NoAbsoluteExpiration, Configs.CacheExpiration); } return (byte[])Context.Cache[key]; }
public static void ParsePngText(string filename, out float normScale, out List <ImageMod> imageMods, out bool thumbOnly, out string originalFilename) { var pngChunkReader = new PngChunkReader(filename); imageMods = new List <ImageMod>(); originalFilename = null; thumbOnly = false; normScale = 1.0f; foreach (var c in pngChunkReader.Chunks) { var type = Encoding.UTF8.GetString(c.Type); // It's actually capitalized like this if (!string.IsNullOrEmpty(type) && type == "tEXt") { var val = Encoding.UTF8.GetString(c.Data); if (!string.IsNullOrEmpty(val)) { if (val.StartsWith("NormScale")) { var splitVals = val.Split('\0'); if (splitVals.Length >= 2) { normScale = (float)Convert.ToDouble(splitVals[1]); } } else if (val.StartsWith("OriginalImage")) { var splitVals = val.Split('\0'); if (splitVals.Length >= 2) { originalFilename = splitVals[1]; } } else if (val.StartsWith("ThumbOnly")) { var splitVals = val.Split('\0'); if (splitVals.Length >= 2 && splitVals[1].ToLower() == "yes") { thumbOnly = true; } } else if (val.StartsWith("ImageMod")) { var splitVals = val.Split('\0'); if (splitVals.Length >= 2) { //"%d %d %d %d %d" int op = 0; int val1 = 0; int val2 = 0; int val3 = 0; int val4 = 0; var secondLevelSplit = splitVals[1].Split(' '); if (secondLevelSplit.Length >= 1) { op = Convert.ToInt32(secondLevelSplit[0]); } if (secondLevelSplit.Length >= 2) { val1 = Convert.ToInt32(secondLevelSplit[1]); } if (secondLevelSplit.Length >= 3) { val2 = Convert.ToInt32(secondLevelSplit[2]); } if (secondLevelSplit.Length >= 4) { val3 = Convert.ToInt32(secondLevelSplit[3]); } if (secondLevelSplit.Length >= 5) { val4 = Convert.ToInt32(secondLevelSplit[4]); } var mod = new ImageMod((ImageModType)op, val1, val2, val3, val4); imageMods.Add(mod); } } } } } }
public Stream Get(Stream file, int width, int height, ImageMod imageMod, string hexBackgroundColour, AnchorPosition? anchor, OutputFormat outputFormat) { return ResizeUtility.Get(loadImage(file) ?? getDefault(width, height), width, height, imageMod, hexBackgroundColour, anchor).GetStream(outputFormat); }