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

Replace rectangle with an image.

Engaged ,
Jun 29, 2016 Jun 29, 2016

What would be an easy way to programmatically replace a rectangle (either a solid or a shape) with an image? I'm assuming that the image has the same aspect ratio as the initial rectangle. Thanks!

TOPICS
Scripting
1.6K
Translate
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 1 Correct answer

Contributor , Jul 06, 2016 Jul 06, 2016

try this (where comp.layer(1) is a solid with properties, keyframed or not, that you want to apply to the image -- I didn't test this with a shape layer):

var proj = app.project; 

var comp;

for (var i = 1; i <= proj.numItems; i++){

  if (proj.item(i) instanceof CompItem){

  comp = proj.item(i);

  }

}

var shape1 = comp.layer(1); 

var importOpts = new ImportOptions(new File("/yourDirectory/yourImage.png")); 

var importImg = proj.importFile(importOpts); 

shape1.replaceSource(importImg,false);

Translate
New Here ,
Jul 04, 2016 Jul 04, 2016

Place an image or object into a PDF

  • Choose Tools > Edit PDF > Add Image .

  • In the Open dialog box, locate the file you want to place.

  • Select the image file, and click Open.

  • Click where you want to place the image, or click-drag to size the image as you place it.

    A copy of the image file appears on the page, with the same resolution as the original file.

Translate
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 ,
Jul 05, 2016 Jul 05, 2016

This example works for a local file and gives you the idea of how to duplicate properties and then remove the "replaced" layer.

var proj = app.project;

var comp = proj.item(1);

var shape1 = comp.layer(1);

var importOpts = new ImportOptions(new File("/yourDirectoryName/yourImageFile.png"));

var importImg = app.project.importFile(importOpts);

var myImg = comp.layers.add(importImg);

myImg.inPoint = shape1.inPoint;

myImg.outPoint = shape1.outPoint;

myImg.property("Position").setValue(shape1.property("Position").value);

myImg.property("Scale").setValue(shape1.property("Scale").value);

shape1.remove();

Translate
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
Engaged ,
Jul 05, 2016 Jul 05, 2016

Translate
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 ,
Jul 06, 2016 Jul 06, 2016

try this (where comp.layer(1) is a solid with properties, keyframed or not, that you want to apply to the image -- I didn't test this with a shape layer):

var proj = app.project; 

var comp;

for (var i = 1; i <= proj.numItems; i++){

  if (proj.item(i) instanceof CompItem){

  comp = proj.item(i);

  }

}

var shape1 = comp.layer(1); 

var importOpts = new ImportOptions(new File("/yourDirectory/yourImage.png")); 

var importImg = proj.importFile(importOpts); 

shape1.replaceSource(importImg,false);

Translate
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
Engaged ,
Jul 07, 2016 Jul 07, 2016
LATEST

A solid works perfectly for this. Thanks!!!

Translate
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