• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Resize canvas width to 60% of the height.

Community Beginner ,
Apr 12, 2022 Apr 12, 2022

Copy link to clipboard

Copied

Hi,

 

I was wondering if it's possible to resize the width of an image canvas to a specific % of the height? Let's say my image is 800px by 1000px, but i want the width to be 60% of the height which equals 600px, is there a tool that allows me to do that?

 

The problem with the "Image -> Canvas Size -> Percent" is that if i put 60% in the width field, it will reduce the width to 60% of 800px, not 60% of the 1000px height.

 

I am also looking for a way to do the same thing with the Content-Aware Scale function.

 

I would very much appreciate it if any good samaritan could enlighten me.

TOPICS
Actions and scripting , iPadOS , macOS , Windows

Views

766

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Apr 12, 2022 Apr 12, 2022

You could do this: In the Canvas Size dialog, highlight the Height field (in pixels), and copy it to the clipboard. Highlight the Width field, and paste the Height field into it, followed by "*0.6" ("times 60%"), and click OK.

 

Votes

Translate

Translate
Community Expert , Apr 22, 2022 Apr 22, 2022

@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.

 

Th

...

Votes

Translate

Translate
Adobe
LEGEND ,
Apr 12, 2022 Apr 12, 2022

Copy link to clipboard

Copied

Why can't you set the units from pixels to the percentage you wish, whatever dimension you want to be 60% (in this case height)? It is going to change the aspect ratio and pop a warning of this.

I get 60% of 1000 (600 pixels) as seen below.

Canvas60Percent.jpg

Author “Color Management for Photographers" & "Photoshop CC Color Management/pluralsight"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 12, 2022 Apr 12, 2022

Copy link to clipboard

Copied

You could do this: In the Canvas Size dialog, highlight the Height field (in pixels), and copy it to the clipboard. Highlight the Width field, and paste the Height field into it, followed by "*0.6" ("times 60%"), and click OK.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 12, 2022 Apr 12, 2022

Copy link to clipboard

Copied

I second the approach offered by @Semaphoric – if you need this automated, then you would need a script, such as this basic example:

 

var savedRuler = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var W = activeDocument.height.value * 0.6; // 60%
activeDocument.resizeCanvas(W, null, AnchorPosition.MIDDLECENTER);
app.preferences.rulerUnits = savedRuler;

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 22, 2022 Apr 22, 2022

Copy link to clipboard

Copied

Thank you very much @Stephen_A_Marsh !

 

By any chance, would you know how to do the exact same thing while being Content-Aware so that it resizes the canvas with the object centered? Kind of like what the Content-Aware Scale function does.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 22, 2022 Apr 22, 2022

Copy link to clipboard

Copied

@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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 22, 2022 Apr 22, 2022

Copy link to clipboard

Copied

EDIT: I combined this post with the previous post as the original code was redundant.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 22, 2022 Apr 22, 2022

Copy link to clipboard

Copied

@Boute240157133512 

 

I'm curious, why do you have to resize the doc width to 60% of the doc height? This would generally be performed via cropping with a preset ratio.

 

Edit: I believe that I have answered my own question, a 0.60:1 / 1.2:2  aspect ratio image is also 3:5 aspect ratio using GCD or Farey ratio formulas or 16:9 aspect ratio in Bridge.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 22, 2022 Apr 22, 2022

Copy link to clipboard

Copied

Hi @Stephen_A_Marsh , thank you for your feedback and shout out to @Semaphoric and @TheDigitalDog as well for taking the time to help.

 

Unfortunately, the script didn't work this time, it kind of squashed the subject which is not ideal for my purpose.

 

You're right about the cropping, i'm essentially trying to crop the doc width to 60% of the height while positioning the subject in the middle.

 

I hope the screenshots can help;

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 22, 2022 Apr 22, 2022

Copy link to clipboard

Copied

@Boute240157133512 – Now that you have posted an image, I have something to work with.

 

1. Roughly crop the original down so that it is roughly centred and as wide as possible (the original is off-center and has weird unnecessary space to either side)

 

2. Select menu > Subject

 

3. Save selection as Alpha 1

 

4. Deselect

 

In the script, change the original protection % placeholder value of 50:

 

contentAwareTransformProtected(0, 0, W, 100, true, true, 50, "Alpha 1");

 

To 100 for full protection based on Alpha 1:

 

contentAwareTransformProtected(0, 0, W, 100, true, true, 100, "Alpha 1");

 

Run the script.

 

Enjoy!

 

Edit: I have attached the result. If this is what you are looking for, it is easy enough to add the steps 2-4 from above to the updated 1.1 script.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2022 Apr 23, 2022

Copy link to clipboard

Copied

 

@Boute240157133512 – It may just be easier to manually perform a 9:16 crop ratio:

 

9-16-crop.jpg

 

This is "close enough" to 60% width to height (1125 vs. 1200 px).

 

The script is better for automation if you have many such model shots to batch process.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2022 Apr 23, 2022

Copy link to clipboard

Copied

LATEST

 

We had another similar topic for batch auto-cropping of sports photography portraits:

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-help-crop-based-on-select-subj...

 

There were a few action and script-based solutions, with the following "general purpose" script coming out of the topic:

 

https://www.marspremedia.com/software/photoshop/auto-crop

 

Here I have used a 16:9 ratio – 1125x2000px with 50px margin with content-aware fill on:

 

auto-crop-gui.jpg

 

I have attached the result.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines