need help with resizeCanvas script

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Andrash

need help with resizeCanvas script

Post by Andrash »

Hi all,

would be great if someone can help me out to polish this: I need to run a script, which is resizeing the canvas to a certain size according to it's ratio / orientation. The ratio and orientation check is already done and working but I can't manage to incrase the canvas size in my desired way.

Here is the code:


Code: Select all//set ruler units to CM
var orig_ruler_units = preferences.rulerUnits;
preferences.rulerUnits = Units.CM;
app.preferences.typeUnits = TypeUnits.POINTS

// resize canvas to A4 portrait or landscape according to the ratio of activeDocument
if (width>height){
   activeDocument.resizeCanvas(24.5, 20.8, AnchorPosition.MIDDLECENTER);
   activeDocument.resizeCanvas(21, 29.7, AnchorPosition.TOPCENTER);
   }else{
      if(width<height){
      activeDocument.resizeCanvas(20, 28.5, AnchorPosition.MIDDLECENTER);
      activeDocument.resizeCanvas(21, 29.7, AnchorPosition.BOTTOMCENTER);
   }}

The layout I have to acchieve is shown in the attachment. Any help is welcome )

Regards,
Andrash
Mike Hale

need help with resizeCanvas script

Post by Mike Hale »

I think this might be closer to what you want for the vertical images. I'm not clear how you want the horizontal images to look.
Code: Select all...
}else{
      activeDocument.resizeCanvas(21, 23.5, AnchorPosition.BOTTOMCENTER);
      activeDocument.resizeCanvas(21, 29.7, AnchorPosition.TOPCENTER);
   }
Andrash

need help with resizeCanvas script

Post by Andrash »

Hi Mike,
Thanks for getting your hands on this.

I've tested it out on my CS4 and this is exactly what I need. It only works if I copy it exactly as you wrote (behind the "else").
I attach the Layout for landscape orientation so I might learn from the understanding where the script differs.

Andrash


PS: why can I not attach a file to a follow up replay?
Andrash

need help with resizeCanvas script

Post by Andrash »

I actually can not even attach any file (there is no option to choose "attach file") even when posting a new entry, nor in pm or any where?!? Am I wrong?

Andrash
Andrash

need help with resizeCanvas script

Post by Andrash »

Mike,

thank you so much. I had to try n error a little bit but in the end, the script does exactly what I need! Here is the code for the landscape orientation:


Code: Select all// set canvas size according to orientation
if (height<width){
   activeDocument.resizeCanvas(29.2, 20, AnchorPosition.TOPLEFT);
   activeDocument.resizeCanvas(29.7, 21, AnchorPosition.BOTTOMRIGHT);
   }else{
      if(width<height){
      activeDocument.resizeCanvas(21, 23.5, AnchorPosition.BOTTOMCENTER);
      activeDocument.resizeCanvas(21, 29.7, AnchorPosition.TOPCENTER);
   }}

kind regards,
Andrash
Mike Hale

need help with resizeCanvas script

Post by Mike Hale »

Glad you got it working. We try to keep attachments in the upload section.

I should point out that, unless you have another if statement for width == height that you didn't post, square images will not get a canvas resize.

That's why I dropped the second if statement in the code I posted. If it's not horizontal ( if part ) it must be vertical or square ( else part ). You only need a second if statement if you want square images to get a different resize.

Mike