Is it possible to square and export a JPEG image like this in .NET (without 3rd party tools)?
The method is to extend the canvas (as a white matte) while keeping the image centered and extending the short dimension of the canvas i.e.
if width is 300 and height is 480 then extend the canvas width to be 480.
ps = new Photoshop.Application();
ps.Preferences.RulerUnits = PsUnits.psPixels;
Console.WriteLine(f.FullName);
ps.Open(f.FullName);
// unlock background to allow canvas resizing
ps.ActiveDocument.ActiveLayer.name = "From Background";
ps.ActiveDocument.ChangeMode(PsChangeMode.psConvertToRGB);
// resize canvas to square
double width = ps.ActiveDocument.Width;
double height = ps.ActiveDocument.Height;
if (width > height)
{
ps.ActiveDocument.ResizeCanvas(width, width,
PsAnchorPosition.psMiddleCenter);
}
else if (width < height)
{
ps.ActiveDocument.ResizeCanvas(height, height,
PsAnchorPosition.psMiddleCenter);
}
in this before/after i used a gray background in the after image so it is easy to see, but I will use a white matte in prodcution.