Exemple #1
0
        public String ProcessImageByAction(UserImageDto img)
        {
            var result = String.Empty;
            switch (img.Action)
            {
                case "VerifyCoverPic":
                    {
                        result = VerifyImageSize(img.SourceUrl, 800, 200);
                    }
                    break;
                case "VerifyProfilePic":
                    {
                        result = VerifyProfilePicImageSize(img.SourceUrl);
                    }
                    break;
                case "PreviewCoverPic":
                    {
                        result = ImagePreview(img, 595, 800);
                    }
                    break;

                case "SaveCoverPic":
                    {
                        result = SaveCoverImage(img);
                    }
                    break;
                case "SaveProfilePic":
                    {
                        result = SaveProfileImage(img);
                    }
                    break;
             default:
                    return String.Empty;
            }
            return result;
        }
Exemple #2
0
        private string SaveProfileImage(UserImageDto img)
        {
            var imgMemoryStream = new MemoryStream();
            var user = new UserDto { ID = img.UserId };
            var src = img.SourceUrl.Substring(img.SourceUrl.IndexOf(',') + 1);
            byte[] data = Convert.FromBase64String(src);

            Image imgPhoto = Image.FromStream(new MemoryStream(data));
            var newImage = new Bitmap(160, 160);
            Graphics.FromImage(newImage).DrawImage(imgPhoto, 0, 0, 160, 160);

            newImage.Save(imgMemoryStream, ImageFormat.Jpeg);

            byte[] modifiedImage = imgMemoryStream.GetBuffer();
            user.ProfileImage = modifiedImage;
            _userRepository.UpdateUserProfileImage(_autoMap.Map<UserDto, User>(user));

            return img.SourceUrl;
        }
Exemple #3
0
        private string ImagePreview(UserImageDto img, int maxHeight, int maxWidth)
        {
            byte[] src;
            var currentImage = img.SourceUrl.Substring(img.SourceUrl.IndexOf(',') + 1);
            byte[] data = Convert.FromBase64String(currentImage);

            Image imgPhoto = Image.FromStream(new MemoryStream(data));
            var height = imgPhoto.Height;
            var width = imgPhoto.Width;

            if (height > maxHeight && width > maxWidth)
            {
                var newImage = new Bitmap(maxWidth, maxHeight);
                Graphics.FromImage(newImage).DrawImage(imgPhoto, 0, 0, maxWidth, maxHeight);
                src = CropImageFile(newImage, img.Width, img.Height, img.X, img.Y);
            }
            else if(height > maxHeight )
            {
                var newImage = new Bitmap(maxWidth, maxHeight);
                Graphics.FromImage(newImage).DrawImage(imgPhoto, 0, 0, width, maxHeight);
                src = CropImageFile(newImage, img.Width, img.Height, img.X, img.Y);
            }
            else if(width > maxWidth )
            {
                var newImage = new Bitmap(maxWidth, maxHeight);
                Graphics.FromImage(newImage).DrawImage(imgPhoto, 0, 0, maxWidth, height);
                src = CropImageFile(newImage, img.Width, img.Height, img.X, img.Y);
            }
            else
            {
                src = CropImageFile(imgPhoto, 800, 200, img.X, img.Y);
            }
            var imageForPreview = Convert.ToBase64String(src);
            return imageForPreview;
        }
Exemple #4
0
 private string SaveCoverImage(UserImageDto img)
 {
     var user = new UserDto {ID = img.UserId};
     var src = img.SourceUrl.Substring(img.SourceUrl.IndexOf(',') + 1);
     byte[] data = Convert.FromBase64String(src);
     user.CoverImage = data;
     _userRepository.UpdateUserCoverImage(_autoMap.Map<UserDto,User >(user));
     return img.SourceUrl;
 }
Exemple #5
0
 public HttpResponseMessage Post(UserImageDto img)
 {
     var response = _imageFacade.ProcessImageByAction(img);
     return Request.CreateErrorResponse(HttpStatusCode.Created, response);
 }