public IActionResult AddBase64([FromBody] AnimalAddViewModel model)
        {
            string imageName = Guid.NewGuid().ToString() + ".jpg";
            string base64    = model.Image;

            if (base64.Contains(","))
            {
                base64 = base64.Split(',')[1];
            }

            var    bmp         = base64.FromBase64StringToImage();
            string fileDestDir = _env.ContentRootPath;

            fileDestDir = Path.Combine(fileDestDir, _configuration.GetValue <string>("ImagesPath"));

            string fileSave = Path.Combine(fileDestDir, imageName);

            if (bmp != null)
            {
                int size  = 1200;
                var image = ImageHelper.CompressImage(bmp, size, size);
                image.Save(fileSave, ImageFormat.Jpeg);
            }
            //bmp.Save(fileSave);

            //Random rand = new Random();
            //_context.Animals.Add(new DbAnimal
            //{
            //    Name = model.Name,
            //    Image = model.Image
            //});
            //_context.SaveChanges();
            return(Ok());
        }
Exemple #2
0
        public IActionResult AddBase64([FromBody] AnimalAddViewModel model)
        {
            string imageName = Guid.NewGuid().ToString() + ".jpg";
            string base64    = model.Image;

            if (base64.Contains(","))
            {
                base64 = base64.Split(',')[1];
            }
            var    bmp         = base64.FromBase64StringToImage();
            string fileDestDir = _env.ContentRootPath;

            //string a = _configuration.GetValue<string>("ImagesPath");
            fileDestDir = Path.Combine(fileDestDir, "Uploaded");

            string fileSave = Path.Combine(fileDestDir, imageName);

            bmp.Save(fileSave);

            //_context.Animals.Add(new DbAnimal
            //{
            //    Name = model.Name,
            //    Image = model.Image
            //});
            //_context.SaveChanges();
            return(Ok());
        }
 public IActionResult Post([FromBody] AnimalAddViewModel model)
 {
     //Random rand = new Random();
     _context.Animals.Add(new DbAnimal
     {
         Name  = model.Name,
         Image = model.Image
     });
     _context.SaveChanges();
     return(Ok());
 }
        public IActionResult AddBase64([FromBody] AnimalAddViewModel model)
        {
            //string imageName = Guid.NewGuid().ToString() + ".jpg";
            string base64 = model.Image;

            if (base64.Contains(","))
            {
                base64 = base64.Split(',')[1];
            }

            var    bmp         = base64.FromBase64StringToImage();
            string fileDestDir = _env.ContentRootPath;

            fileDestDir = Path.Combine(fileDestDir, _configuration.GetValue <string>("ImagesPath"));


            //string fileSave = Path.Combine(fileDestDir, imageName);
            if (bmp != null)
            {
                int    size         = 300;
                string imageName300 = Guid.NewGuid().ToString() + "300.jpg";
                string fileSave300  = Path.Combine(fileDestDir, imageName300);
                var    image300     = ImageHelper.CompressImage(bmp, size, size);
                image300.Save(fileSave300, ImageFormat.Jpeg);

                size = 600;
                string imageName600 = Guid.NewGuid().ToString() + "600.jpg";
                string fileSave600  = Path.Combine(fileDestDir, imageName600);
                var    image600     = ImageHelper.CompressImage(bmp, size, size);
                image600.Save(fileSave600, ImageFormat.Jpeg);


                size = 1200;
                string imageName1200 = Guid.NewGuid().ToString() + "1200.jpg";
                string fileSave1200  = Path.Combine(fileDestDir, imageName1200);
                var    image1200     = ImageHelper.CompressImage(bmp, size, size);
                image1200.Save(fileSave1200, ImageFormat.Jpeg);
            }
            //string fileSave = Path.Combine(fileDestDir, imageName);

            //if (bmp!=null)
            //{
            //    var size = 200;
            //}

            //bmp.Save(fileSave);



            return(Ok());
        }
Exemple #5
0
        public IActionResult AdBase64([FromBody] AnimalAddViewModel model)
        {
            var sizes = _configuration.GetValue <string>("ImagesSizes").Split(' ');


            string imageName = Guid.NewGuid().ToString() + ".jpg";
            string base64    = model.Image;

            if (base64.Contains(","))
            {
                base64 = base64.Split(',')[1];
            }

            var    bmp         = base64.FromBase64StringToImage();
            string fileDestDir = _env.ContentRootPath;

            fileDestDir = Path.Combine(fileDestDir, _configuration.GetValue <string>("ImagesPath"));

            foreach (var element in sizes)
            {
                string fileSave = Path.Combine(fileDestDir, element + "_" + imageName);
                if (bmp != null)
                {
                    int size  = Convert.ToInt32(element);
                    var image = ImageHelper.CompressImage(bmp, size, size);
                    image.Save(fileSave, ImageFormat.Jpeg);
                }
            }

            _context.Animals.Add(new DbAnimal
            {
                Name  = model.Name,
                Image = imageName
            });
            _context.SaveChanges();



            return(Ok());
        }