wip logo
This commit is contained in:
parent
d2ab7bfce6
commit
ce58f99de1
3 changed files with 77 additions and 56 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
public enum Positions
|
public enum Positions
|
||||||
{
|
{
|
||||||
Alto,
|
Alto,
|
||||||
|
Centro,
|
||||||
Basso
|
Basso
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -210,51 +210,10 @@ namespace CatalogLib
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
// todo calcolare ridimensionamento
|
// todo calcolare ridimensionamento
|
||||||
var size = new Size();
|
var size = new Size(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza);
|
||||||
if (PicSettings.Instance.FotoMantieniDimensioni)
|
if (PicSettings.Instance.FotoMantieniDimensioni)
|
||||||
{
|
{
|
||||||
|
size = ResizeImage(image, size, PicSettings.Instance.ResizeDimension);
|
||||||
|
|
||||||
|
|
||||||
switch (PicSettings.Instance.ResizeDimension)
|
|
||||||
{
|
|
||||||
case ResizeDimensions.LatoLungo:
|
|
||||||
if (image.Width > image.Height)
|
|
||||||
{
|
|
||||||
// larghezza è il lato lungo
|
|
||||||
size = GetResizeDimensions(new Size(image.Width, image.Height),
|
|
||||||
new Size(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
|
||||||
true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// altezza è il lato lungo
|
|
||||||
size = GetResizeDimensions(new Size(image.Width, image.Height),
|
|
||||||
new Size(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
|
||||||
false);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ResizeDimensions.LatoCorto:
|
|
||||||
if (image.Width > image.Height)
|
|
||||||
{
|
|
||||||
// larghezza è il lato lungo
|
|
||||||
size = GetResizeDimensions(new Size(image.Width, image.Height),
|
|
||||||
new Size(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
|
||||||
false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// altezza è il lato lungo
|
|
||||||
size = GetResizeDimensions(new Size(image.Width, image.Height),
|
|
||||||
new Size(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
|
||||||
true);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new ArgumentOutOfRangeException();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
image.Mutate(x => x.Resize((size.Width), (size.Height), resampler));
|
image.Mutate(x => x.Resize((size.Width), (size.Height), resampler));
|
||||||
|
|
||||||
//Width Formula:
|
//Width Formula:
|
||||||
|
|
@ -270,16 +229,25 @@ namespace CatalogLib
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Size GetResizeDimensions(Size originalSize, Size newSize, bool isWidth)
|
private Size ResizeImage(Image<Rgba32> image, Size size, ResizeDimensions side)
|
||||||
{
|
{
|
||||||
if (isWidth)
|
switch (side)
|
||||||
{
|
{
|
||||||
return new Size(newSize.Width, originalSize.Height / originalSize.Width * newSize.Height);
|
case ResizeDimensions.LatoLungo:
|
||||||
}
|
size = GetResizeDimensions(new Size(image.Width, image.Height), size, image.Width > image.Height);
|
||||||
else
|
break;
|
||||||
{
|
case ResizeDimensions.LatoCorto:
|
||||||
return new Size(originalSize.Width / originalSize.Height * newSize.Height, newSize.Height);
|
size = GetResizeDimensions(new Size(image.Width, image.Height), size, image.Width <= image.Height);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Size GetResizeDimensions(Size originalSize, Size newSize, bool adjustHeight)
|
||||||
|
{
|
||||||
|
return adjustHeight ? new Size(newSize.Width, originalSize.Height / originalSize.Width * newSize.Height) : new Size(originalSize.Width / originalSize.Height * newSize.Height, newSize.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetTextTest(Image<Rgba32> image)
|
private void SetTextTest(Image<Rgba32> image)
|
||||||
|
|
@ -488,29 +456,63 @@ namespace CatalogLib
|
||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
Size size = new Size();
|
||||||
|
Point location = new Point();
|
||||||
|
|
||||||
if (_logo != null)
|
if (_logo != null)
|
||||||
{
|
{
|
||||||
var width = PicSettings.Instance.LogoWidth;
|
var width = PicSettings.Instance.LogoWidth;
|
||||||
var height = PicSettings.Instance.LogoHeight;
|
var height = PicSettings.Instance.LogoHeight;
|
||||||
var fattoreAlt = _logo.Height / height;
|
var heightFactor = _logo.Height / height;
|
||||||
var fattoreLarg = _logo.Width / width;
|
var widthFactor = _logo.Width / width;
|
||||||
var nuovaSize = new Size();
|
var newLogoSize = new Size();
|
||||||
|
|
||||||
nuovaSize = GetResizeDimensions(new Size(_logo.Width, _logo.Height), new Size(width, height), fattoreLarg > fattoreAlt);
|
newLogoSize = GetResizeDimensions(new Size(_logo.Width, _logo.Height), new Size(width, height), PicSettings.Instance.LogoResizeSide.Equals(ResizeDimensions.LatoCorto));
|
||||||
//todo riguardare perché non torna cosa ho fatto
|
//todo riguardare perché non torna cosa ho fatto
|
||||||
|
|
||||||
int margineUsato;
|
int margineUsato = 0;
|
||||||
int margineL;
|
int margineL;
|
||||||
bool inPercentualeL;
|
bool inPercentualeL;
|
||||||
|
|
||||||
inPercentualeL = PicSettings.Instance.LogoMargin.EndsWith("%");
|
inPercentualeL = PicSettings.Instance.LogoMargin.EndsWith("%");
|
||||||
if (inPercentualeL)
|
if (inPercentualeL)
|
||||||
{ margineL = int.Parse(PicSettings.Instance.LogoMargin.Replace("%", ""));}
|
{
|
||||||
|
margineL = int.Parse(PicSettings.Instance.LogoMargin.Replace("%", ""));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
margineL = int.Parse(PicSettings.Instance.LogoMargin);
|
margineL = int.Parse(PicSettings.Instance.LogoMargin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (PicSettings.Instance.LogoPosition)
|
||||||
|
{
|
||||||
|
case Positions.Alto:
|
||||||
|
break;
|
||||||
|
case Positions.Centro:
|
||||||
|
break;
|
||||||
|
case Positions.Basso:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (PicSettings.Instance.LogoAlignment)
|
||||||
|
{
|
||||||
|
case Alignments.Sinistra:
|
||||||
|
location.X = margineUsato;
|
||||||
|
break;
|
||||||
|
case Alignments.Centro:
|
||||||
|
//location.X = image.Width -
|
||||||
|
break;
|
||||||
|
case Alignments.Destra:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
}
|
||||||
|
image.Mutate(x => x.DrawImage(_logo, size, location, new GraphicsOptions()));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -519,6 +519,24 @@ namespace CatalogLib
|
||||||
set => SetString("LogoMargin", value);
|
set => SetString("LogoMargin", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Positions LogoPosition
|
||||||
|
{
|
||||||
|
get => GetEnum("LogoPositions", Positions.Alto);
|
||||||
|
set => SetString("LogoPositions", value.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Alignments LogoAlignment
|
||||||
|
{
|
||||||
|
get => GetEnum("LogoAlignments", Alignments.Centro);
|
||||||
|
set => SetString("LogoAlignments", value.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResizeDimensions LogoResizeSide
|
||||||
|
{
|
||||||
|
get => GetEnum("LogoResizeMode", ResizeDimensions.LatoCorto);
|
||||||
|
set => SetString("LogoResizeMode", value.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Enums
|
#region Enums
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue