diff --git a/src/ImageProcessor/ImageFactory.cs b/src/ImageProcessor/ImageFactory.cs
index 9b683491ed..94061c8eee 100644
--- a/src/ImageProcessor/ImageFactory.cs
+++ b/src/ImageProcessor/ImageFactory.cs
@@ -38,6 +38,11 @@ namespace ImageProcessor
///
private ImageFormat backupImageFormat;
+ ///
+ /// The original extension.
+ ///
+ private string originalExtension;
+
///
/// Whether the image is indexed.
///
@@ -184,6 +189,7 @@ namespace ImageProcessor
this.JpegQuality = DefaultJpegQuality;
ImageFormat imageFormat = ImageUtils.GetImageFormat(imageName);
this.backupImageFormat = imageFormat;
+ this.originalExtension = Path.GetExtension(imagePath);
this.ImageFormat = imageFormat;
this.isIndexed = ImageUtils.IsIndexed(this.Image);
this.ShouldProcess = true;
@@ -612,7 +618,7 @@ namespace ImageProcessor
// We need to check here if the path has an extension and remove it if so.
// This is so we can add the correct image format.
int length = filePath.LastIndexOf(".", StringComparison.Ordinal);
- string extension = ImageUtils.GetExtensionFromImageFormat(this.ImageFormat);
+ string extension = ImageUtils.GetExtensionFromImageFormat(this.ImageFormat, this.originalExtension);
filePath = length == -1 ? filePath + extension : filePath.Substring(0, length) + extension;
// Fix the colour palette of indexed images.
diff --git a/src/ImageProcessor/Imaging/ImageUtils.cs b/src/ImageProcessor/Imaging/ImageUtils.cs
index f8e69233c4..58a9568aba 100644
--- a/src/ImageProcessor/Imaging/ImageUtils.cs
+++ b/src/ImageProcessor/Imaging/ImageUtils.cs
@@ -102,10 +102,13 @@ namespace ImageProcessor.Imaging
///
/// The to return the extension for.
///
+ ///
+ /// The original Extension.
+ ///
///
/// The correct file extension for the given .
///
- public static string GetExtensionFromImageFormat(ImageFormat imageFormat)
+ public static string GetExtensionFromImageFormat(ImageFormat imageFormat, string originalExtension)
{
switch (imageFormat.ToString())
{
@@ -117,8 +120,18 @@ namespace ImageProcessor.Imaging
return ".png";
case "Tif":
case "Tiff":
+ if (!string.IsNullOrWhiteSpace(originalExtension) && originalExtension.ToUpperInvariant() == ".TIFF")
+ {
+ return ".tiff";
+ }
+
return ".tif";
default:
+ if (!string.IsNullOrWhiteSpace(originalExtension) && originalExtension.ToUpperInvariant() == ".JPEG")
+ {
+ return ".jpeg";
+ }
+
return ".jpg";
}
}