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

Re-size Image in ExtendScript

New Here ,
Jan 06, 2014 Jan 06, 2014

Copy link to clipboard

Copied

I have a script for After Effects, I want the user to be able to set a max dimmensions on an image. I'm getting the dimmensions with

AVItem.height & AVItem.width

But how do I change these values? In the documentation I've found:


"

In a CompItem, the value is linked to the composition, and is read/write.

In a FootageItem, the value is linked to the mainSource object, and is read/write only if the mainSource

object is a SolidSource. Otherwise, it is read-only.

"

In my case this is not a 'SolidSource' type, how can I change the dimmensions? Any work arounds? Besides creating a new CompItem and inserting the image and then changing the values of the CompItem

TOPICS
Scripting

Views

3.7K

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
Advocate ,
Jan 06, 2014 Jan 06, 2014

Copy link to clipboard

Copied

In my case this is not a 'SolidSource' type, how can I change the dimmensions?

I think you may have answered your own question. If you are not dealing with a SolidSource then you can only read the values, not change them.

In a CompItem, the value is linked to the composition, and is read/write.

In a FootageItem, the value is linked to the mainSource object, and is read/write only if the mainSource

object is a SolidSource. Otherwise, it is read-only.

What is your main intention? Are you trying to limit the size of images brought into the AE project, or are you just trying to set a max size for the image as it enters a composition?

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
New Here ,
Jan 07, 2014 Jan 07, 2014

Copy link to clipboard

Copied

Thanks David, I'm pretty much trying to implement a "max height/max width" function.

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
New Here ,
Feb 19, 2014 Feb 19, 2014

Copy link to clipboard

Copied

David Torno wrote:

What is your main intention? Are you trying to limit the size of images brought into the AE project, or are you just trying to set a max size for the image as it enters a composition?

That's what I'm trying to do, too. I found an expression that can be applied to the Scale for an image, but I want to be able to import the image, resize it to the longest side, and add it as a layer to a comp (preexisting, or per image). Ultimately, I want to be able to do a for loop or a while loop through all the images and display them in a master comp. The forums here and at Creative Cow has been quite helpful at building the script so far, but I'm stuck at this point, too.

Thanks in advance for any advice on this. I've been searching, but haven't found the right info yet.

Dion

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
Advocate ,
Feb 19, 2014 Feb 19, 2014

Copy link to clipboard

Copied

but I want to be able to import the image, resize it to the longest side, and add it as a layer to a comp

This will resize a layer that exists in a comp timeline.

I made a function based off of Dan Ebberts code found here: http://forums.adobe.com/message/4588192#4588192

Two ways to process the layers...

A) You would process each new layer as it is added in your loop.

B) You can process all the layers after you've added them to the comp.

//Requires two arguments

imageSizeToCompSize(compObj, layerObj);

function imageSizeToCompSize(compObj, layerObj){

          var curLayerBoundry, curLayerScale, newLayerScale;

          curLayerBoundry = layerObj.sourceRectAtTime(0,false);

          curLayerScaleObj = layerObj.property("ADBE Transform Group").property("ADBE Scale");

          curLayerScaleVal = curLayerScaleObj.value;

          newLayerScale = curLayerScaleVal*Math.min(compObj.width/curLayerBoundry.width, compObj.height/curLayerBoundry.height);

          curLayerScaleObj.setValue(newLayerScale);

}

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
New Here ,
Feb 20, 2014 Feb 20, 2014

Copy link to clipboard

Copied

David Torno wrote:

but I want to be able to import the image, resize it to the longest side, and add it as a layer to a comp

This will resize a layer that exists in a comp timeline.

I made a function based off of Dan Ebberts code found here: http://forums.adobe.com/message/4588192#4588192

This is brilliant, David, thank you! I was able to modify that slightly to make the layer half the size of the comp. Ideally I'd be able to do it as a percentage of the master comp, but this is an excellent start.

I've been playing with some of your code from this post: http://forums.adobe.com/message/6082239

Now with the above function and a few other snippets, I am this ->...<- close to achieving my goal.

Next step: Adding fades to the layers.

Once I've got it, I'll post it to the forum seperately for folks to see.

Thank you.

Dion

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
Advocate ,
Feb 21, 2014 Feb 21, 2014

Copy link to clipboard

Copied

If you wanna go the expression route, you could automate the layer fades without having to create keyframes. if you added this expression to the Opacity property of the layer.

fadeTime = 10;

opacityMin = 0;

opacityMax = 100;

layerDuration = outPoint - inPoint;

singleFrame = thisComp.frameDuration;

animateIn = linear(time, inPoint, (inPoint + framesToTime(fadeTime)), opacityMin, opacityMax);

animateOut = linear(time, (outPoint - framesToTime(fadeTime+1)), (outPoint-singleFrame), opacityMax, opacityMin);

if(time < (layerDuration/2)){

          animateIn;

}else{

          animateOut;

}

You could set it up like so...

//Frames that fade will take place over

var fade = "10";

//encoded expression string with "fade" variable inserted

var myExpress = "fadeTime%20=%20" + fade + ";%0DopacityMin%20=%200;%0DopacityMax%20=%20100;%0DlayerDuration%20=%20outPoint%20-%20inPoint;%0DsingleFrame%20=%20thisComp.frameDuration;%0DanimateIn%20=%20linear(time,%20inPoint,%20(inPoint%20+%20framesToTime(fadeTime)),%20opacityMin,%20opacityMax);%0DanimateOut%20=%20linear(time,%20(outPoint%20-%20framesToTime(fadeTime+1)),%20(outPoint-singleFrame),%20opacityMax,%20opacityMin);%0Dif(time%20%3C%20(layerDuration/2))%7B%0D%09animateIn;%0D%7Delse%7B%0D%09animateOut;%0D%7D";

//Applies expression

myLayerOpacityProperty.expression = decodeURI(myExpress);

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
New Here ,
Feb 23, 2014 Feb 23, 2014

Copy link to clipboard

Copied

Oh. Wow. Haven't been able to try this yet, but that looks awesome. I did script it using keyframes, but using an expression looks good, too.

Is there a benefit to using expressions versus keyframes?

I was working through one of your ExtendScript tutorials that creates a script to get the properties of an object. Trying to figure out how to add a frame around the images as they are presented. Trying to mask and then generate stroke (although I'm sure I saw a different method).

Which raises this issue, is it better to:

a) put the images directly into a comp and manipulate them that way

b) add each image to its own comp, manipulate the images in their comp and then add all the image comps to a master comp

c) add each image to its own comp, and the image comps to a master comp and then manipulate the image comps

Not sure if there is a "best practise" guideline for this, or a "whatever works best for you" guideline.

Thanks for your help.

Dion

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
Advocate ,
Feb 24, 2014 Feb 24, 2014

Copy link to clipboard

Copied

LATEST

Is there a benefit to using expressions versus keyframes?

Pros and Cons. For this particular instance, the pro would be that you do not need keyframes, and if you changed the in or the out point of the layer, you fade would adjust by itself still work. If you did it via keyframes, you gotta place them, then remove them if you change any timing of the layer, and then reapply them. More coding involved. The cons would be if there were a lot of layers using an expression, you might see a slight processing time hit when working or rendering.

Which raises this issue, is it better to:

a) put the images directly into a comp and manipulate them that way

b) add each image to its own comp, manipulate the images in their comp and then add all the image comps to a master comp

c) add each image to its own comp, and the image comps to a master comp and then manipulate the image comps

D) Any of the above. It just boils down to what kind of control do you need over the source footage. I usually have the source footage in a precomp and use the precomp and the "source footage". It makes it easy to change the main footage if need be. I deal with a lot of template style building in AE, so it just comes naurally when I build things.

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