Пример #1
0
        public void ImageUrl(int id, int width = 60, int height = 60)
        {
            //    var fileManagers = GetStoreImages();
            var images = FileManagerService.GetFilesById(id);  //fileManagers.FirstOrDefault(r => r.Id == id);

            if (images != null)
            {
                String url       = images.WebContentLink;
                var    dic       = new Dictionary <String, String>();
                byte[] imageData = GeneralHelper.GetImageFromUrlFromCache(url, dic);
                if (width > 0 && height > 0)
                {
                    float ratio = images.Width.ToFloat() / images.Height.ToFloat();
                    height = (int)(width * ratio);
                    new WebImage(imageData)
                    .Resize(width, height, false, true) // Resizing the image to 100x100 px on the fly...
                    .Crop(1, 1)                         // Cropping it to remove 1px border at top and left sides (bug in WebImage)
                    .Write();
                }
                else
                {
                    new WebImage(imageData)
                    .Crop(1, 1)     // Cropping it to remove 1px border at top and left sides (bug in WebImage)
                    .Write();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Reference this in HTML as <img src="/Photo/WatermarkedImage/{ID}" />
        /// Simplistic example supporting only jpeg images.
        /// </summary>
        /// <param name="ID">Photo ID</param>
        public ActionResult WatermarkedImage(int id)
        {
            // Attempt to fetch the photo record from the database using Entity Framework 4.2.
            var file = FileManagerService.GetFilesById(id);

            if (file != null) // Found the indicated photo record.
            {
                var dic = new Dictionary <String, String>();
                // Create WebImage from photo data.
                // Should have 'using System.Web.Helpers' but just to make it clear...
                String url       = String.Format("https://docs.google.com/uc?id={0}", file.GoogleImageId);
                byte[] imageData = GeneralHelper.GetImageFromUrl(url, dic);
                var    wi        = new System.Web.Helpers.WebImage(imageData);

                // Apply the watermark.
                wi.AddTextWatermark("EMIN YUCE");

                // Extract byte array.
                var image = wi.GetBytes("image/jpeg");

                // Return byte array as jpeg.
                return(File(image, "image/jpeg"));
            }
            else // Did not find a record with passed ID.
            {
                return(null); // 'Missing image' icon will display on browser.
            }
        }