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,16 +96,19 @@ namespace ManagerService.Helpers
currentImage = resizedImage; currentImage = resizedImage;
} }
Font font = new Font("Arial", 25, FontStyle.Italic, GraphicsUnit.Pixel); if(watermark)
Color color = Color.DarkBlue;
Point point = new Point(currentImage.Width /2, (int)Math.Round(currentImage.Height - currentImage.Height * 0.1));
SolidBrush brush = new SolidBrush(color);
using (Graphics graphics = Graphics.FromImage(currentImage))
{ {
StringFormat stringFormat = new StringFormat(); Font font = new Font("Arial", 25, FontStyle.Italic, GraphicsUnit.Pixel);
stringFormat.Alignment = StringAlignment.Center; Color color = Color.DarkBlue;
stringFormat.LineAlignment = StringAlignment.Center; Point point = new Point(currentImage.Width /2, (int)Math.Round(currentImage.Height - currentImage.Height * 0.1));
graphics.DrawString("fortsaintheribert.be", font, brush, point, stringFormat); SolidBrush brush = new SolidBrush(color);
using (Graphics graphics = Graphics.FromImage(currentImage))
{
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
graphics.DrawString("fortsaintheribert.be", font, brush, point, stringFormat);
}
} }
using (MemoryStream updatedImageMemorySteam = new MemoryStream()) using (MemoryStream updatedImageMemorySteam = new MemoryStream())