Add watermark and shrink images only if fort

This commit is contained in:
Fransolet Thomas 2023-01-26 17:09:48 +01:00
parent 63654bdcf9
commit 52d5467b85
2 changed files with 21 additions and 12 deletions

View File

@ -242,8 +242,14 @@ namespace ManagerService.Controllers
{ {
file.CopyTo(ms); file.CopyTo(ms);
var fileBytes = ms.ToArray(); var fileBytes = ms.ToArray();
if (resourceType == ResourceType.Image) { if (resourceType == ResourceType.Image)
fileBytes = ImageHelper.ResizeAndAddWatermark(fileBytes, MaxWidth, MaxHeight); {
bool isFort = instanceId == "633ee379d9405f32f166f047"; // If fort saint heribert, TODO add watermark in configuration and model
if(isFort) // TODO We need to know for which purpose (mobile or tablet)
{
fileBytes = ImageHelper.ResizeAndAddWatermark(fileBytes, isFort, MaxWidth, MaxHeight);
}
} }
stringResult = Convert.ToBase64String(fileBytes); stringResult = Convert.ToBase64String(fileBytes);
} }

View File

@ -79,7 +79,7 @@ namespace ManagerService.Helpers
return convertedToBytes; return convertedToBytes;
} }
public static byte[] ResizeAndAddWatermark(Byte[] bytes, int maxWidth, int maxHeight) public static byte[] ResizeAndAddWatermark(Byte[] bytes, bool watermark, int maxWidth, int maxHeight)
{ {
byte[] convertedToBytes; byte[] convertedToBytes;
@ -96,6 +96,8 @@ namespace ManagerService.Helpers
currentImage = resizedImage; currentImage = resizedImage;
} }
if(watermark)
{
Font font = new Font("Arial", 25, FontStyle.Italic, GraphicsUnit.Pixel); Font font = new Font("Arial", 25, FontStyle.Italic, GraphicsUnit.Pixel);
Color color = Color.DarkBlue; Color color = Color.DarkBlue;
Point point = new Point(currentImage.Width /2, (int)Math.Round(currentImage.Height - currentImage.Height * 0.1)); Point point = new Point(currentImage.Width /2, (int)Math.Round(currentImage.Height - currentImage.Height * 0.1));
@ -107,6 +109,7 @@ namespace ManagerService.Helpers
stringFormat.LineAlignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center;
graphics.DrawString("fortsaintheribert.be", font, brush, point, stringFormat); graphics.DrawString("fortsaintheribert.be", font, brush, point, stringFormat);
} }
}
using (MemoryStream updatedImageMemorySteam = new MemoryStream()) using (MemoryStream updatedImageMemorySteam = new MemoryStream())
{ {