Example #1
0
        private PhotoVersion saveImageToDisk(MagickImage image, PhotoTypeEnum type, string fileName)
        {
            var photoName = Guid.NewGuid().ToString() + Path.GetExtension(fileName);

            var path = Path.Combine(Server.MapPath("~/Images/Mediums"), photoName);

            switch (type)
            {
            case PhotoTypeEnum.Thumbnail:

                path = Path.Combine(Server.MapPath("~/Images/Thumbnails"), photoName);

                image.Write(path);

                break;

            case PhotoTypeEnum.Medium:

                image.Write(path);

                break;

            default:
                break;
            }

            return(CreatePhotoVersion(path, type, image.Width, image.Height));
        }
Example #2
0
        private PhotoVersion CreatePhotoVersion(string path, PhotoTypeEnum type, int width, int height)
        {
            var photoVersion = new PhotoVersion();

            photoVersion.Width  = width;
            photoVersion.Height = height;
            photoVersion.Path   = path;
            photoVersion.Type   = type;

            return(photoVersion);
        }
Example #3
0
        public ActionResult GetPhoto(int photoid, PhotoTypeEnum phototype)
        {
            var photo = db.Photos.Find(photoid);

            if (photo == null)
            {
                return(base.File(defaultThumbnailPath, "image/jpeg"));
            }

            var photoVersion = db.PhotoVersions.Where(x => x.PhotoID == photo.ID && x.Type == phototype).FirstOrDefault();

            if (photoVersion == null)
            {
                return(base.File(defaultThumbnailPath, "image/jpeg"));
            }

            return(base.File(photoVersion.Path, "image/jpeg"));
        }
Example #4
0
        private PhotoVersion ResizeImage(string fileName, int typeWidth, int typeHeight, PhotoTypeEnum type)
        {
            using (MagickImage image = new MagickImage(fileName)) //Nu stiu exact daca merge asa direct din HttpPostedFileBase
            {
                MagickImageInfo info = new MagickImageInfo(fileName);

                //fit in dimensiunile respective
                MagickGeometry size = new MagickGeometry(typeWidth, typeHeight);

                if (info.Width > info.Height)
                {
                    //image.Resize(0, typeHeight);

                    image.Resize(size);
                }
                else
                {
                    //image.Resize(typeWidth, 0);

                    image.Resize(size);
                }
                return(saveImageToDisk(image, type, fileName));
            }
        }