LANCommander/LANCommander.PowerShell/Cmdlets/Convert-AspectRatio.cs

46 lines
1.2 KiB
C#
Raw Permalink Normal View History

using System;
using System.Management.Automation;
namespace LANCommander.PowerShell.Cmdlets
{
public class DisplayResolution
{
public int Width { get; set; }
public int Height { get; set; }
}
[Cmdlet(VerbsData.Convert, "AspectRatio")]
[OutputType(typeof(string))]
2023-11-16 21:21:50 +00:00
public class ConvertAspectRatioCmdlet : Cmdlet
{
[Parameter(Mandatory = true, Position = 0)]
public int Width { get; set; }
[Parameter(Mandatory = true, Position = 1)]
public int Height { get; set; }
[Parameter(Mandatory = true, Position = 2)]
public double AspectRatio { get; set; }
protected override void ProcessRecord()
{
var resolution = new DisplayResolution();
// Display is wider, pillar box
if ((Width / Height) < AspectRatio)
{
resolution.Width = (int)Math.Ceiling(Height * AspectRatio);
resolution.Height = Height;
}
// Letterbox
else
{
resolution.Width = Width;
resolution.Height = (int)Math.Ceiling(Width * (1 / AspectRatio));
}
WriteObject(resolution);
}
}
}