Browse Source

Fixing jpeg jpg determination issue

Former-commit-id: f44d73eed02c208b5d042e5560136eb1ec1d2205
af/merge-core
James South 13 years ago
parent
commit
2f60059865
  1. 8
      src/ImageProcessor/ImageFactory.cs
  2. 15
      src/ImageProcessor/Imaging/ImageUtils.cs

8
src/ImageProcessor/ImageFactory.cs

@ -38,6 +38,11 @@ namespace ImageProcessor
/// </summary>
private ImageFormat backupImageFormat;
/// <summary>
/// The original extension.
/// </summary>
private string originalExtension;
/// <summary>
/// Whether the image is indexed.
/// </summary>
@ -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.

15
src/ImageProcessor/Imaging/ImageUtils.cs

@ -102,10 +102,13 @@ namespace ImageProcessor.Imaging
/// <param name="imageFormat">
/// The <see cref="T:System.Drawing.Imaging.ImageFormat"/> to return the extension for.
/// </param>
/// <param name="originalExtension">
/// The original Extension.
/// </param>
/// <returns>
/// The correct file extension for the given <see cref="T:System.Drawing.Imaging.ImageFormat"/>.
/// </returns>
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";
}
}

Loading…
Cancel
Save