public static void ResizeToFixedSize(ThumbnailTypeType type, string imagePath, long fileId, int width = 250, int height = 250) { // Read from file using (var image = new MagickImage(imagePath)) { var size = new MagickGeometry(width, height) { IgnoreAspectRatio = true }; // This will resize the image to a fixed size without maintaining the aspect ratio. // Normally an image will be resized to fit inside the specified size. if (IsResizeNeedsToApply(imagePath, width, height)) { image.Resize(size); } var baseBath = RepositoryHelper.GetThumbnailFilePath(DocumentType.WorkFileUpload, type); baseBath += fileId + "_" + width + "x" + height + ".png"; // Save the result image.Write(baseBath); } }
/// <summary> /// return thumbnail preview path /// </summary> /// <param name="docType"></param> /// <param name="thumbnailType"></param> /// <returns></returns> public static string GetThumbnailFilePath(DocumentType docType, ThumbnailTypeType thumbnailType) { var imageType = thumbnailType == ThumbnailTypeType.Album ? "_album_" : "_photo_"; return(ConfigurationManager.AppSettings["DocumentStorageLocation"] + @"\ImageThumbnails\" + imageType); }