44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
using System.IO;
|
|
|
|
namespace Bring2mind.InMemoriam.Core.Common
|
|
{
|
|
public class Image
|
|
{
|
|
public string ResizedFile { get; set; }
|
|
public bool ImageExists { get; set; }
|
|
private string Location { get; set; }
|
|
|
|
public Image(string location, string id, int width, int height, string method)
|
|
{
|
|
Location = location;
|
|
var filePath = Path.Combine(location, id + ".resources");
|
|
ImageExists = File.Exists(filePath);
|
|
if (ImageExists)
|
|
{
|
|
ResizedFile = $"{id}_{width}_{height}_{method}.jpg";
|
|
var m = ImageResizer.ResizeMethod.Stretch;
|
|
switch (method)
|
|
{
|
|
case "b":
|
|
m = ImageResizer.ResizeMethod.Box;
|
|
break;
|
|
case "c":
|
|
m = ImageResizer.ResizeMethod.Crop;
|
|
break;
|
|
}
|
|
ImageResizer.ResizeImage(filePath, $"{location}\\{ResizedFile}", width, height, m);
|
|
}
|
|
}
|
|
|
|
public void CopyToStream(Stream s)
|
|
{
|
|
var imgFile = ImageExists ? string.Format("{0}\\{1}", Location, ResizedFile) : string.Format("{0}\\images\\no-content.png", DotNetNuke.Common.Globals.ApplicationMapPath);
|
|
using (var fs = new FileStream(imgFile, FileMode.Open, FileAccess.Read))
|
|
{
|
|
fs.CopyTo(s);
|
|
fs.Flush();
|
|
}
|
|
}
|
|
}
|
|
}
|