[英]How to change color swatch of colored greyscale pictures using ExtendScript in InDesign?
I've got the following problem/situation: 我有以下问题/情况:
What I want to do now, is to write a script to color every picture with a different color swatch, eg the picture on page 1 with color swatch "1", the picture on page 2 with color swatch "2" etc. But I don't know how to access the picture itself (instead of the frame) and change its color. 我现在要做的是编写一个脚本,用不同的颜色样本为每张图片着色,例如第1页上的图片,色样“1”,第2页上的图片,色样“2”等。但是我不知道如何访问图片本身(而不是框架)并改变其颜色。 Is this even possible?
这甚至可能吗?
Thanks in advance. 提前致谢。
This should do the trick. 这应该可以解决问题。 It currently sets random color for the images and only looks for rectangles.
它目前为图像设置随机颜色,仅查找矩形。 You could use
你可以用
page.allPageItems
instead. 代替。 (if you also have images in ovals or polygons)
(如果你还有椭圆形或多边形的图像)
// the main function
var main = function() {
var doc = app.activeDocument; // get the current document
// loop the pages
for (var i = 0; i < doc.pages.length; i++) {
var page = doc.pages[i]; // isolate the page
// loop all rectangles
for(var j = 0; j < page.rectangles.length;j++){
var rect = page.rectangles[j]; // isolate a rectangle
// test if there is an image inside
if(rect.images.length > 0){
var image = rect.images[0]; // isolate the image
// asign a random color from th swatches
image.fillColor = doc.swatches[Math.floor(Math.random()* doc.swatches.length -1)];
} // end if image
} // end loop j rectangles
} // end loop i pages
} // end of main
main(); // run it
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.