-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
495 additions
and
548 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace LazZiya.ImageResize.Exceptions | ||
{ | ||
public enum FailureReasonType | ||
{ | ||
None, | ||
EncoderNotFound, | ||
ExtensionNotSupported, | ||
UnknownImageFormatGuid, | ||
ZeroSizeNotAllowed, | ||
GraphicsException | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
LazZiya.ImageResize/ImageResizeException.cs → ...Resize/Exceptions/ImageResizeException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 1 addition & 5 deletions
6
LazZiya.ImageResize/ImageResizeResult.cs → ...ageResize/Exceptions/ImageResizeResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using LazZiya.ImageResize.Exceptions; | ||
using System; | ||
using System.Drawing.Imaging; | ||
|
||
namespace LazZiya.ImageResize | ||
{ | ||
public class ImageFormats | ||
{ | ||
/// <summary> | ||
/// return image format by comparing the ImageFormat.Guid param | ||
/// </summary> | ||
/// <param name="guid"></param> | ||
/// <returns>System.Drawing.Imaging.ImageFormat</returns> | ||
public static ImageFormat GetImageFormat(Guid guid) | ||
{ | ||
return | ||
guid == ImageFormat.Bmp.Guid ? ImageFormat.Bmp : | ||
guid == ImageFormat.Emf.Guid ? ImageFormat.Emf : | ||
guid == ImageFormat.Exif.Guid ? ImageFormat.Exif : | ||
guid == ImageFormat.Gif.Guid ? ImageFormat.Gif : | ||
guid == ImageFormat.Icon.Guid ? ImageFormat.Icon : | ||
guid == ImageFormat.Jpeg.Guid ? ImageFormat.Jpeg : | ||
guid == ImageFormat.MemoryBmp.Guid ? ImageFormat.MemoryBmp : | ||
guid == ImageFormat.Png.Guid ? ImageFormat.Png : | ||
guid == ImageFormat.Tiff.Guid ? ImageFormat.Tiff : | ||
guid == ImageFormat.Wmf.Guid ? ImageFormat.Wmf : | ||
|
||
throw new ImageResizeException(new ImageResizeResult() | ||
{ | ||
Reason = FailureReasonType.UnknownImageFormatGuid, | ||
Success = false, | ||
Value = guid.ToString() | ||
}); | ||
} | ||
|
||
/// <summary> | ||
/// return image format by reading file extension | ||
/// </summary> | ||
/// <param name="fileName"></param> | ||
/// <returns>System.Drawing.Imaging.ImageFormat</returns> | ||
public static ImageFormat GetImageFormat(string fileName) | ||
{ | ||
var dotIndex = fileName.LastIndexOf('.'); | ||
var ext = fileName.Substring(dotIndex, fileName.Length - dotIndex).ToLower(); | ||
|
||
return | ||
ext == ".bmp" ? ImageFormat.Bmp : | ||
ext == ".emf" ? ImageFormat.Emf : | ||
ext == ".exif" ? ImageFormat.Exif : | ||
ext == ".gif" ? ImageFormat.Gif : | ||
ext == ".icon" ? ImageFormat.Icon : | ||
ext == ".jpg" ? ImageFormat.Jpeg : | ||
ext == ".png" ? ImageFormat.Png : | ||
ext == ".tiff" ? ImageFormat.Tiff : | ||
ext == ".wmf" ? ImageFormat.Wmf : | ||
throw new ImageResizeException(new ImageResizeResult() | ||
{ | ||
Reason = FailureReasonType.ExtensionNotSupported, | ||
Success = false, | ||
Value = ext | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.