Browse Source

Fixing jpeg jpg determination issue

Former-commit-id: fd50b51c8cafaa33a0f99210c2279197f59b6682
af/merge-core
James South 13 years ago
parent
commit
14f3d518a8
  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> /// </summary>
private ImageFormat backupImageFormat; private ImageFormat backupImageFormat;
/// <summary>
/// The original extension.
/// </summary>
private string originalExtension;
/// <summary> /// <summary>
/// Whether the image is indexed. /// Whether the image is indexed.
/// </summary> /// </summary>
@ -184,6 +189,7 @@ namespace ImageProcessor
this.JpegQuality = DefaultJpegQuality; this.JpegQuality = DefaultJpegQuality;
ImageFormat imageFormat = ImageUtils.GetImageFormat(imageName); ImageFormat imageFormat = ImageUtils.GetImageFormat(imageName);
this.backupImageFormat = imageFormat; this.backupImageFormat = imageFormat;
this.originalExtension = Path.GetExtension(imagePath);
this.ImageFormat = imageFormat; this.ImageFormat = imageFormat;
this.isIndexed = ImageUtils.IsIndexed(this.Image); this.isIndexed = ImageUtils.IsIndexed(this.Image);
this.ShouldProcess = true; 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. // 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. // This is so we can add the correct image format.
int length = filePath.LastIndexOf(".", StringComparison.Ordinal); 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; filePath = length == -1 ? filePath + extension : filePath.Substring(0, length) + extension;
// Fix the colour palette of indexed images. // Fix the colour palette of indexed images.

15
src/ImageProcessor/Imaging/ImageUtils.cs

@ -102,10 +102,13 @@ namespace ImageProcessor.Imaging
/// <param name="imageFormat"> /// <param name="imageFormat">
/// The <see cref="T:System.Drawing.Imaging.ImageFormat"/> to return the extension for. /// The <see cref="T:System.Drawing.Imaging.ImageFormat"/> to return the extension for.
/// </param> /// </param>
/// <param name="originalExtension">
/// The original Extension.
/// </param>
/// <returns> /// <returns>
/// The correct file extension for the given <see cref="T:System.Drawing.Imaging.ImageFormat"/>. /// The correct file extension for the given <see cref="T:System.Drawing.Imaging.ImageFormat"/>.
/// </returns> /// </returns>
public static string GetExtensionFromImageFormat(ImageFormat imageFormat) public static string GetExtensionFromImageFormat(ImageFormat imageFormat, string originalExtension)
{ {
switch (imageFormat.ToString()) switch (imageFormat.ToString())
{ {
@ -117,8 +120,18 @@ namespace ImageProcessor.Imaging
return ".png"; return ".png";
case "Tif": case "Tif":
case "Tiff": case "Tiff":
if (!string.IsNullOrWhiteSpace(originalExtension) && originalExtension.ToUpperInvariant() == ".TIFF")
{
return ".tiff";
}
return ".tif"; return ".tif";
default: default:
if (!string.IsNullOrWhiteSpace(originalExtension) && originalExtension.ToUpperInvariant() == ".JPEG")
{
return ".jpeg";
}
return ".jpg"; return ".jpg";
} }
} }

Loading…
Cancel
Save