Blog.Common.Utils.Helpers.ImageHelper.CreateThumbnail C# (CSharp) Method

CreateThumbnail() public method

public CreateThumbnail ( string filename, string destinationPath, string thumbnailPrefix ) : bool
filename string
destinationPath string
thumbnailPrefix string
return bool
        public bool CreateThumbnail(string filename, string destinationPath, string thumbnailPrefix)
        {
            try
            {
                var image = Image.FromFile(filename);
                var jgpEncoder = GetEncoder(ImageFormat.Jpeg);
                var encoder = Encoder.Quality;
                var encoderParams = new EncoderParameters(1);

                if (!Directory.Exists(destinationPath.TrimEnd('\\')))
                {
                    FileHelper.CreateDirectory(destinationPath);
                }

                var thumb = ResizeImage(image, GetComputedImageSize(image.Width, image.Height));
                encoderParams.Param[0] = new EncoderParameter(encoder, 100L);
                thumb.Save(destinationPath.TrimEnd('\\') + @"\" + thumbnailPrefix + Path.GetFileName(filename), jgpEncoder, encoderParams);

                thumb.Dispose();
                image.Dispose();

                return true;
            }
            catch (Exception ex)
            {
                throw new BlogException(ex.Message, ex.InnerException);
            }

        }