public static RoboFanImage Fetch(int robofanid, string path) { // create and ensure we are requested to fetch the robot image RoboFanImage fanimage = Create(robofanid); fanimage.ImageData = ReadImage(path); return(fanimage); }
public static RoboFanImage Generate(int robofanid, string imagepath) { // create and read one of the pre-generated robot images RoboFanImage fanimage = Create(robofanid); fanimage.ImageData = ReadImage(imagepath); return(fanimage); }
public static async Task <RoboFanImage> GenerateAsync(int robofanid, string imagepath) { // create and read one of the pre-generated robot images RoboFanImage fanimage = Create(robofanid); fanimage.ImageData = await ReadImageAsync(imagepath); return(fanimage); }
private static RoboFanImage Create(int robofanid) { const int imgwidth = 80; const int imgheight = 80; // create and initialize the values RoboFanImage fanimage = new RoboFanImage(); fanimage.Id = robofanid; fanimage.GuidId = Guid.NewGuid(); fanimage.Width = imgwidth; fanimage.Height = imgheight; fanimage.ContentType = "image/png"; fanimage.RoboFanId = robofanid; return(fanimage); }
public static string ImageUrl(RoboFanImage fanimage, string hostpath = null) { string imageurl; // determine if the hostpath was specified if (!string.IsNullOrEmpty(hostpath)) { // build up a full URL path for the image imageurl = string.Format("{0}/api/robofan/{1}/image", hostpath, fanimage.Id); } else { // build up a relative path for the image imageurl = string.Format("~/api/robofan/{0}/image", fanimage.Id); } return(imageurl); }
public static RoboFanImage Generate(int robofanid, bool fetchImage = true) { // create and ensure we are requested to fetch the robot image RoboFanImage fanimage = Create(robofanid); if (fetchImage) { // create web client to download robot images with using (var client = new WebClient()) { // generate a random robot image using the robohash website and download the image data var imageurl = string.Format("https://robohash.org/robots/{0}?size={1}x{2}", fanimage.GuidId, fanimage.Width, fanimage.Height); fanimage.ImageData = client.DownloadData(imageurl); } } return(fanimage); }