Open biasmey opened 9 years ago
Could you please change this code in ImageResult and upgrade nuget .
thx
private static string GetResizedImagePath(string filepath, int width, int height) { var resizedPath = filepath;
if (width <= 0 && height <= 0)
return resizedPath;
resizedPath = filepath.GetPathForResizedImage(width, height);
if (!Directory.Exists(resizedPath))
{
var directoryName = new FileInfo(resizedPath).DirectoryName;
if (directoryName != null)
Directory.CreateDirectory(directoryName);
}
if (File.Exists(resizedPath))
return resizedPath;
var encode = GetEncode(filepath);
var imageResizer = new ImageResizer(filepath);
if (width > 0 && height > 0)
{
imageResizer.Resize(width, height, encode);
}
else if (width > 0)
{
imageResizer.Resize(width, encode);
}
imageResizer.SaveToFile(resizedPath);
imageResizer.Dispose();
return resizedPath;
}
private static ImageEncoding GetEncode(string filepath) { ImageFormat imageFormat; using (var image = new Bitmap(filepath)) { imageFormat = image.RawFormat; }
if (Equals(imageFormat, ImageFormat.Bmp))
return ImageEncoding.Bmp;
if (Equals(imageFormat, ImageFormat.Gif))
return ImageEncoding.Gif;
if (Equals(imageFormat, ImageFormat.Jpeg))
return ImageEncoding.Jpg90;
if (Equals(imageFormat, ImageFormat.Png))
return ImageEncoding.Png;
return Equals(imageFormat, ImageFormat.Tiff) ? ImageEncoding.Tiff : ImageEncoding.Jpg100;
}
I am using ImageResult(filepath, with, height) in my project but it always encode image using type 2. thx