Ridimensionamento e opzioni
This commit is contained in:
parent
a81451bd6b
commit
9fd336befb
7 changed files with 212 additions and 18 deletions
|
|
@ -9,6 +9,7 @@ using MaddoLibrary.Base.Log;
|
|||
using SixLabors.Fonts;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Drawing;
|
||||
using SixLabors.ImageSharp.Formats.Jpeg;
|
||||
using SixLabors.ImageSharp.MetaData.Profiles.Exif;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using SixLabors.Primitives;
|
||||
|
|
@ -52,11 +53,10 @@ namespace CatalogLib
|
|||
|
||||
if (PicSettings.Instance.FotoRidimensiona)
|
||||
{
|
||||
// todo calcolare ridimensionamento
|
||||
image.Mutate(x => x.Resize(PicSettings.Instance.FotoAltezza, PicSettings.Instance.FotoLarghezza, new BicubicResampler()));
|
||||
Resize(image);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (PicSettings.Instance.GeneraleRotazioneAutomatica)
|
||||
{
|
||||
image.Mutate(img => img.AutoOrient());
|
||||
|
|
@ -125,8 +125,8 @@ namespace CatalogLib
|
|||
if (PicSettings.Instance.EnableText)
|
||||
{
|
||||
//SetTextTest(image);
|
||||
SetExtraText(image, isRotated);
|
||||
|
||||
SetExtraText(image, isRotated);
|
||||
|
||||
|
||||
MaddoLogger.Log("Drawn text on Image: {0}", workFile.FullName);
|
||||
}
|
||||
|
|
@ -141,7 +141,7 @@ namespace CatalogLib
|
|||
//var fff = FontCollection.SystemFonts.Find(PicSettings.Instance.NomeFont);
|
||||
//var font = new Font(fff, (float)PicSettings.Instance.DimensioneFont, FontStyle.Regular);
|
||||
//image.DrawText("sssssssssssssssssssssssssssssssssssssssssssssss", font, Color.Black, new Vector2(200, 200));
|
||||
image.Save(Path.Combine(PicSettings.Instance.DirectoryDestinazione, workFile.Name));
|
||||
image.Save(Path.Combine(PicSettings.Instance.DirectoryDestinazione, workFile.Name), new JpegEncoder(){Quality = PicSettings.Instance.CompressioneJpeg});
|
||||
//image.Resize(200, 200).Save("");
|
||||
|
||||
MaddoLogger.Log("Saved Image: {0} to: {1}", workFile.FullName, Path.Combine(PicSettings.Instance.DirectoryDestinazione, workFile.Name));
|
||||
|
|
@ -150,6 +150,129 @@ namespace CatalogLib
|
|||
MaddoLogger.Log("Time Taken for {0}: {1}", workFile.FullName, s.Elapsed);
|
||||
}
|
||||
|
||||
private void Resize(Image<Rgba32> image)
|
||||
{
|
||||
IResampler resampler;
|
||||
switch (PicSettings.Instance.ResizeMode)
|
||||
{
|
||||
case ResizeModes.Bicubic:
|
||||
resampler = new BicubicResampler();
|
||||
break;
|
||||
case ResizeModes.Box:
|
||||
resampler = new BoxResampler();
|
||||
break;
|
||||
case ResizeModes.CatmullRom:
|
||||
resampler = new CatmullRomResampler();
|
||||
break;
|
||||
case ResizeModes.Hermite:
|
||||
resampler = new HermiteResampler();
|
||||
break;
|
||||
case ResizeModes.Lanczos2:
|
||||
resampler = new Lanczos2Resampler();
|
||||
break;
|
||||
case ResizeModes.Lanczos3:
|
||||
resampler = new Lanczos3Resampler();
|
||||
break;
|
||||
case ResizeModes.Lanczos5:
|
||||
resampler = new Lanczos5Resampler();
|
||||
break;
|
||||
case ResizeModes.Lanczos8:
|
||||
resampler = new Lanczos8Resampler();
|
||||
break;
|
||||
case ResizeModes.MitchellNetravali:
|
||||
resampler = new MitchellNetravaliResampler();
|
||||
break;
|
||||
case ResizeModes.NearestNeighbor:
|
||||
resampler = new NearestNeighborResampler();
|
||||
break;
|
||||
case ResizeModes.Robidoux:
|
||||
resampler = new RobidouxResampler();
|
||||
break;
|
||||
case ResizeModes.Spline:
|
||||
resampler = new SplineResampler();
|
||||
break;
|
||||
case ResizeModes.Triangle:
|
||||
resampler = new TriangleResampler();
|
||||
break;
|
||||
case ResizeModes.Welch:
|
||||
resampler = new WelchResampler();
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
// todo calcolare ridimensionamento
|
||||
var size = new Vector2();
|
||||
if (PicSettings.Instance.FotoMantieniDimensioni)
|
||||
{
|
||||
|
||||
|
||||
|
||||
switch (PicSettings.Instance.ResizeDimension)
|
||||
{
|
||||
case ResizeDimensions.LatoLungo:
|
||||
if (image.Width > image.Height)
|
||||
{
|
||||
// larghezza è il lato lungo
|
||||
size = GetResizeDimensions(new Vector2(image.Width, image.Height),
|
||||
new Vector2(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
||||
true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// altezza è il lato lungo
|
||||
size = GetResizeDimensions(new Vector2(image.Width, image.Height),
|
||||
new Vector2(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
||||
false);
|
||||
}
|
||||
break;
|
||||
case ResizeDimensions.LatoCorto:
|
||||
if (image.Width > image.Height)
|
||||
{
|
||||
// larghezza è il lato lungo
|
||||
size = GetResizeDimensions(new Vector2(image.Width, image.Height),
|
||||
new Vector2(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
||||
false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// altezza è il lato lungo
|
||||
size = GetResizeDimensions(new Vector2(image.Width, image.Height),
|
||||
new Vector2(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
||||
true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
|
||||
|
||||
}
|
||||
image.Mutate(x => x.Resize((int)Math.Round(size.X), (int)Math.Round(size.Y), resampler));
|
||||
|
||||
//Width Formula:
|
||||
//original height / original width * new width = new height
|
||||
//Height Formula:
|
||||
//orignal width / orignal height * new height = new width
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
image.Mutate(x => x.Resize(PicSettings.Instance.FotoAltezza, PicSettings.Instance.FotoLarghezza, resampler));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Vector2 GetResizeDimensions(Vector2 originalSize, Vector2 newSize, bool isWidth)
|
||||
{
|
||||
if (isWidth)
|
||||
{
|
||||
return new Vector2(newSize.X, originalSize.Y / originalSize.X * newSize.X);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Vector2(originalSize.X / originalSize.Y * newSize.Y, newSize.Y);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetTextTest(Image<Rgba32> image)
|
||||
{
|
||||
string text = "test test test test test testtest test test test test test test";
|
||||
|
|
@ -204,9 +327,9 @@ namespace CatalogLib
|
|||
font = new Font(fo, (float)PicSettings.Instance.DimensioneFont, FontStyle.Bold);
|
||||
}
|
||||
// todo corsivo
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//var font = new Font(fff, 8f, FontStyle.Regular);
|
||||
|
||||
|
||||
|
|
@ -227,7 +350,7 @@ namespace CatalogLib
|
|||
var size = TextMeasurer.Measure(text, new RendererOptions(font));
|
||||
|
||||
var larghezzaStandard = size.Width;
|
||||
var dimensioneStandard = (int) Math.Round(PicSettings.Instance.DimensioneFont);
|
||||
var dimensioneStandard = (int)Math.Round(PicSettings.Instance.DimensioneFont);
|
||||
if (size.Width > image.Width)
|
||||
{
|
||||
var c = dimensioneStandard;
|
||||
|
|
@ -254,7 +377,7 @@ namespace CatalogLib
|
|||
new RendererOptions(font));
|
||||
if (size.Width < image.Width)
|
||||
{
|
||||
larghezzaStandard = (int) Math.Round(size.Width);
|
||||
larghezzaStandard = (int)Math.Round(size.Width);
|
||||
break;
|
||||
}
|
||||
if (c <= 5)
|
||||
|
|
@ -277,7 +400,7 @@ namespace CatalogLib
|
|||
}
|
||||
|
||||
float xCenterofImg = 0;
|
||||
|
||||
|
||||
// stringformat
|
||||
|
||||
switch (PicSettings.Instance.TextAlignment)
|
||||
|
|
@ -313,7 +436,7 @@ namespace CatalogLib
|
|||
font = new Font(fo, dimensioneStandard, FontStyle.Regular);
|
||||
}
|
||||
|
||||
image.Mutate(x => x.DrawText(text, font, gBack, new PointF((float)Math.Round(xCenterofImg + 1) , (float)Math.Round(yPosFromBottom + 1)), new TextGraphicsOptions()
|
||||
image.Mutate(x => x.DrawText(text, font, gBack, new PointF((float)Math.Round(xCenterofImg + 1), (float)Math.Round(yPosFromBottom + 1)), new TextGraphicsOptions()
|
||||
{
|
||||
HorizontalAlignment = HorizontalAlignment.Center
|
||||
}));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue