Initial commit
This commit is contained in:
43
Server/Core/Common/Image.cs
Normal file
43
Server/Core/Common/Image.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user