@Boute240157133512 – Thank you for marking my script post as a correct answer. I marked the reply from @Semaphoric as correct as all I did was put that reply into a simple script, so full credit to Semaphoric!
Please try the following content-aware version. It is only for flattened images, although it could easily work with a single-layered image too. You can mark this new script as a correct answer if it works for you. Please let me know how it goes and if any modifications are required.
This revised version adds the "protection" parameter which uses Alpha 1 to protect areas from the content-aware transform with a 50% protection value:
/*
https://community.adobe.com/t5/photoshop-ecosystem-discussions/resize-canvas-width-to-60-of-the-height/m-p/12899014
v1.1, Stephen Marsh, 23rd April 2022
*/
#target photoshop
app.bringToFront();
var savedRuler = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// 0.6 = 60%
var W = activeDocument.height.value * 0.6 / activeDocument.width.value * 100;
if (app.activeDocument.activeLayer.isBackgroundLayer) {
activeDocument.activeLayer.name = 'Content Aware Scale Temp';
contentAwareTransformProtected(0, 0, W, 100, true, true, 100, "Alpha 1");
app.activeDocument.trim(TrimType.TRANSPARENT);
app.activeDocument.flatten();
deleteAlphaByName("Alpha 1");
} else {
alert("This script is only intended for flattened images!");
}
app.preferences.rulerUnits = savedRuler;
function deleteAlphaByName(chaName) {
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var reference = new ActionReference();
reference.putName( s2t( "channel" ), chaName );
descriptor.putReference( s2t( "null" ), reference );
executeAction( s2t( "delete" ), descriptor, DialogModes.NO );
}
function contentAwareTransformProtected(horizontal, vertical, width, height, contentAware, skinTone, amount, channelName) {
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
var reference = new ActionReference();
reference.putEnumerated( s2t( "layer" ), s2t( "ordinal" ), s2t( "targetEnum" ));
descriptor.putReference( s2t( "null" ), reference );
descriptor.putEnumerated( s2t( "freeTransformCenterState" ), s2t( "quadCenterState" ), s2t( "QCSAverage" ));
descriptor2.putUnitDouble( s2t( "horizontal" ), s2t( "pixelsUnit" ), horizontal );
descriptor2.putUnitDouble( s2t( "vertical" ), s2t( "pixelsUnit" ), vertical );
descriptor.putObject( s2t( "offset" ), s2t( "offset" ), descriptor2 );
descriptor.putUnitDouble( s2t( "width" ), s2t( "percentUnit" ), width );
descriptor.putUnitDouble( s2t( "height" ), s2t( "percentUnit" ), height );
descriptor.putEnumerated( s2t( "interfaceIconFrameDimmed" ), s2t( "interpolationType" ), s2t( "bicubic" ));
descriptor.putBoolean( s2t( "contentAware" ), contentAware );
descriptor.putBoolean( s2t( "skinTone" ), skinTone );
descriptor.putDouble( s2t( "amount" ), amount );
descriptor.putString( s2t( "channelName" ), channelName );
executeAction( s2t( "transform" ), descriptor, DialogModes.NO );
}
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html