예제 #1
0
 public static void DeleteImages(string postId)
 {
     BlobRepository.DeleteFolder(postId, BlobRepository.PostsContainer);
 }
예제 #2
0
 public static void DeleteImages(string trackId)
 {
     BlobRepository.DeleteFolder(trackId, BlobRepository.TracksContainer);
 }
예제 #3
0
        // images
        private static async Task <bool> ProcessImage(string postId, string imageUrl)
        {
            using (WebClient webClient = new WebClient())
            {
                byte[] data        = webClient.DownloadData(imageUrl);
                string contentType = webClient.ResponseHeaders["Content-Type"];

                // check correct content type
                if ("image/jpeg" != contentType)
                {
                    return(false);
                }

                /// generate mini
                using (MemoryStream input = new MemoryStream(data))
                {
                    using (MemoryStream output = new MemoryStream())
                    {
                        Images.CropSquare(48, input, output);

                        using (output)
                        {
                            await BlobRepository.UploadFileAsync(BlobRepository.PostsContainer, output.ToArray(), postId + "/thumb_mini", contentType);
                        }
                    }
                }

                // generate thumb
                using (MemoryStream input = new MemoryStream(data))
                {
                    using (MemoryStream output = new MemoryStream())
                    {
                        Images.CropSquare(150, input, output);

                        using (output)
                        {
                            await BlobRepository.UploadFileAsync(BlobRepository.PostsContainer, output.ToArray(), postId + "/thumb", contentType);
                        }
                    }
                }

                // hero
                using (MemoryStream input = new MemoryStream(data))
                {
                    using (MemoryStream output = new MemoryStream())
                    {
                        Images.GenerateHero(400, input, output);

                        using (output)
                        {
                            await BlobRepository.UploadFileAsync(BlobRepository.PostsContainer, output.ToArray(), postId + "/hero", contentType);
                        }
                    }
                }

                // resized
                using (MemoryStream input = new MemoryStream(data))
                {
                    using (MemoryStream output = new MemoryStream())
                    {
                        Images.Resize(800, input, output);

                        using (output)
                        {
                            await BlobRepository.UploadFileAsync(BlobRepository.PostsContainer, output.ToArray(), postId + "/large", contentType);
                        }
                    }
                }

                return(true);
            }
        }