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

Need help with a script to resize (crop) a comp from the center rather than top left

Contributor ,
May 01, 2020 May 01, 2020

Copy link to clipboard

Copied

I'm working on a project that needs all comps sized at 2000x2000. They're based on PSD files at varying sizes (most over 2000x2000,  a few below that). I have to manually resize each comp to 2000x2000 using the GUI,  but NOT scale the layer contents – so essentially this is a crop. And it's quite tedious to do manually every single time.

 

So I want to create a script that does it for me which I'll add to a ScriptUI button. This partially works…

 

 

// Get active comp
var comp = app.project.activeItem;

// Resize to 2000x2000
comp.height = 2000;
comp.width = 2000;

 

 

 …however it crops from the top left. I need it to crop from the center of the original comp.

 

I think I can get the center of the original comp with…

compCenter = [thisComp.width / 2, thisComp.height / 2];

 …but I'm not sure how to plug that into the resize section above.

 

Any help is appreciated!

TOPICS
How to , Scripting

Views

391

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 ,
May 01, 2020 May 01, 2020

Copy link to clipboard

Copied

It might be as simple as this, depending on whether there's stuff going on in the comp that you didn't mention:

 

var comp = app.project.activeItem;
comp.height = 2000;
comp.width = 2000;
compCenter = [comp.width / 2, comp.height / 2];
for (var i = 1; i <= comp.numLayers; i++){
	comp.layer(i).property("Position").setValue(compCenter);
}

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
Contributor ,
May 01, 2020 May 01, 2020

Copy link to clipboard

Copied

Dan the man! Thank you so much, you've helped me immeasurably over the years.

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
Contributor ,
May 01, 2020 May 01, 2020

Copy link to clipboard

Copied

Oops looks like I was too hasty in my marking of this as the correct answer 🙂 My fault. While your solution DOES give me a center crop, it moves all the layers to the center. I failed to mention that I don't want the original layers in the comp to move to the center.  Every layer needs to remain exactly in place because they're imported at layer size, not document size. Is this possible?

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
Contributor ,
May 01, 2020 May 01, 2020

Copy link to clipboard

Copied

LATEST

Perhaps I could have the script create a solid at the original comp size, parent everything to that solid, resize the comp, center the solid, then delete the solid. I'm not sure how to do all that though as I'm fairly new to scripting. Perhaps there is a more elegant solution than what I just suggested haha.

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