Example #1
0
        public override IList <Photo> SavePhotoForAllSizes(IPhotoRequest item, bool keepOriginalSize)
        {
            var photoResizes = PhotoManager.PhotoResizes;

            using (var stream = item.Stream)
            {
                string extension = GetExtension(item.MimeType);
                string name      = string.Format("{0}{1}", DateTime.UtcNow.ToString("dd_MM_yyyy_hh_mm_ss_ffff"), extension);

                List <Photo> photos =
                    photoResizes.Select(
                        resize =>
                        SaveImage(
                            stream,
                            resize.Value.Width,
                            resize.Value.Height,
                            resize.Key,
                            name,
                            item.MimeType ?? "image/jpeg")).ToList();

                if (keepOriginalSize)
                {
                    using (Image image = Image.FromStream(stream))
                    {
                        var photo = SaveImage(
                            stream, image.Width, image.Height, null, name, item.MimeType ?? "image/jpeg");
                        photos.Add(photo);
                    }
                }

                return(photos);
            }
        }
Example #2
0
        public override Photo SavePhotoResize(IPhotoRequest item, string resizeName)
        {
            // todo: if resizeName doesn't exist, then we need to throw an exception
            var photoResize = PhotoManager.PhotoResizes[resizeName];

            using (var stream = item.Stream)
            {
                string extension = GetExtension(item.MimeType);
                string name      = string.Format("{0}{1}", DateTime.UtcNow.ToString("dd_MM_yyyy_hh_mm_ss_ffff"), extension);
                var    photo     = SaveImage(
                    stream, photoResize.Width, photoResize.Height, resizeName, name, item.MimeType ?? "image/jpeg");

                return(photo);
            }
        }
 /// <summary>
 /// The save photo resize.
 /// </summary>
 /// <param name="item">
 /// The item.
 /// </param>
 /// <param name="resizeName">
 /// The resize name.
 /// </param>
 /// <returns>
 /// The JamesRocks.Photos.Models.Photo.
 /// </returns>
 public abstract Photo SavePhotoResize(IPhotoRequest item, string resizeName);
 /// <summary>
 /// The save photo for all sizes.
 /// </summary>
 /// <param name="item">
 /// The item.
 /// </param>
 /// <param name="keepOriginalSize">
 /// The keep original size.
 /// </param>
 /// <returns>
 /// The System.Collections.Generic.IList`1[T -&gt; JamesRocks.Photos.Models.Photo].
 /// </returns>
 public abstract IList<Photo> SavePhotoForAllSizes(IPhotoRequest item, bool keepOriginalSize);
 /// <summary>
 /// The save photo for all sizes.
 /// </summary>
 /// <param name="item">
 /// The item.
 /// </param>
 /// <param name="keepOriginalSize">
 /// The keep original size.
 /// </param>
 /// <returns>
 /// The System.Collections.Generic.IList`1[T -&gt; JamesRocks.Photos.Models.Photo].
 /// </returns>
 public abstract IList <Photo> SavePhotoForAllSizes(IPhotoRequest item, bool keepOriginalSize);
 /// <summary>
 /// The save photo resize.
 /// </summary>
 /// <param name="item">
 /// The item.
 /// </param>
 /// <param name="resizeName">
 /// The resize name.
 /// </param>
 /// <returns>
 /// The JamesRocks.Photos.Models.Photo.
 /// </returns>
 public abstract Photo SavePhotoResize(IPhotoRequest item, string resizeName);
        public override Photo SavePhotoResize(IPhotoRequest item, string resizeName)
        {
            // todo: if resizeName doesn't exist, then we need to throw an exception
            var photoResize = PhotoManager.PhotoResizes[resizeName];

            using (var stream = item.Stream)
            {
                string extension = GetExtension(item.MimeType);
                string name = string.Format("{0}{1}", DateTime.UtcNow.ToString("dd_MM_yyyy_hh_mm_ss_ffff"), extension);
                var photo = SaveImage(
                    stream, photoResize.Width, photoResize.Height, resizeName, name, item.MimeType ?? "image/jpeg");

                return photo;
            }
        }
        public override IList<Photo> SavePhotoForAllSizes(IPhotoRequest item, bool keepOriginalSize)
        {
            var photoResizes = PhotoManager.PhotoResizes;

            using (var stream = item.Stream)
            {
                string extension = GetExtension(item.MimeType);
                string name = string.Format("{0}{1}", DateTime.UtcNow.ToString("dd_MM_yyyy_hh_mm_ss_ffff"), extension);

                List<Photo> photos =
                    photoResizes.Select(
                        resize =>
                        SaveImage(
                            stream,
                            resize.Value.Width,
                            resize.Value.Height,
                            resize.Key,
                            name,
                            item.MimeType ?? "image/jpeg")).ToList();

                if (keepOriginalSize)
                {
                    using (Image image = Image.FromStream(stream))
                    {
                        var photo = SaveImage(
                            stream, image.Width, image.Height, null, name, item.MimeType ?? "image/jpeg");
                        photos.Add(photo);
                    }
                }

                return photos;
            }
        }