一套 library 可以讓你無 server 配合 Github 做出一套 Image Service ,因為這是 library 版本 ,如果你是想要直接使用 Server 版本,你可以到這裡 https://github.com/donma/N2ImageAgent.AzureBlob2020 ,使用 Azure 版本,除非我找時間來寫 sever 版本
Happy Coding :)
//your_github_token get from : https://github.com/settings/tokens
var containerInfo = new N2ImageAgentGithub.ContainerInfo("your_github_token", "your_username", "yout_reponame");
var agent = new N2ImageAgentGithub.Agent(containerInfo);
Console.WriteLine("Upload Image To Source");
agent.UpoloadImageToSource("test1", AppDomain.CurrentDomain.BaseDirectory + "sample1.jpg", "test upload image source");
Console.WriteLine("Upload Image To Source from byte[]");
agent.UpoloadImageToSource("test1", File.ReadAllBytes(AppDomain.CurrentDomain.BaseDirectory + "sample1.jpg"), "測試上傳:"+DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
Console.WriteLine("Get Image Info And Upload");
var info = Utility.GetImageInfo(AppDomain.CurrentDomain.BaseDirectory + "sample1.jpg", "imageid", "taginfo");
Console.WriteLine(JsonConvert.SerializeObject(info));
agent.UpoloadImageInfo(info, "測試上傳:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
Console.WriteLine("Delete Source and Info");
agent.DeleteSource("imageid");
agent.DeleteImageInfo("imageid");
Console.WriteLine("Delete All Thumb");
agent.DeleteAllImageById("imageid",1000);
Console.WriteLine("Check image in Source");
agent.IsSourceExisted("imageid");
Console.WriteLine("Check image info is existed");
agent.IsImageInfoExisted("imageid");
Console.WriteLine("Check image info is existed");
agent.IsImageThumbExisted("imageid");
//source
var source_url = agent.GetImageThumbFromSource("imageid", 0, 0);
Console.WriteLine(source_url);
//thumb1 : get width 100 and height depend on width.
var thumb1 = agent.GetImageThumbFromSource("imageid", 100, 0);
Console.WriteLine(thumb1);
//thumb2 : get height 200 and width depend on height.
var thumb2 = agent.GetImageThumbFromSource("imageid", 0, 200);
Console.WriteLine(thumb2);