Photoshop脚本 - 交换一段图像

时间:2013-10-31 23:55:41

标签: batch-file swap photoshop-script

我对Photoshop脚本很陌生,我想做以下事情:

批量转换图像,对于每个图像,交换一个像*,

的片段
 _____________________
|                     |
|                     |
|                     |
|______         ______|
|      |       |      |
|  9   |       |   E  |
|______|       |______|
|                     |
|                     |
|                     |
|                     |
|                     |
|_____________________|

成为这个:

 _____________________
|                     |
|                     |
|                     |
|______         ______|
|      |       |      |
|  3   |       |   e  |
|______|       |______|
|                     |
|                     |
|                     |
|                     |
|                     |
|_____________________|

我只想知道我该怎么做,哪些功能等等。关于位置,我不能确切地说出哪个像素,所以,请给我一个例子,我计算一下我必须使用的数字

  • 考虑到 3 类似于 E 的水平翻转,与 {{1 e

1 个答案:

答案 0 :(得分:1)

这是完成这项工作的脚本。其中大部分都是使用script listener编写的。脚本监听器代码看起来很糟糕,但过了一段时间,你可以放入脚本监听器代码的snipets并将它们变成函数。这就是我所做的。 您没有指定图像的大小,因此此脚本适用于100像素×100像素的图像,并将翻转所选图层。指定坐标的幻数用于选择此行代码。根据自己的需要改变它。

如果您有兴趣学习如何为photoshop编写代码,那么我建议您使用(并学习)javaScript。哦,看看脚本监听器。玩得开心。

//Set the preference to be pixels
app.preferences.rulerUnits = Units.PIXELS;

// Call the source document
var srcDoc = app.activeDocument;

// make sure we don't have anything selected first
srcDoc.selection.deselect()

// call the two selected areas
selectThis(33, 0, 33, 67, 33, 67, 100, 67);

//  flip the selection horizontally
flipEm()


// function SELECT THIS(top, left, right, bottom)
// --------------------------------------------------------
function selectThis(top1, left1, right1, bottom1, top2, left2, right2, bottom2)
{

  // =======================================================
  var id8699 = charIDToTypeID( "setd" );
  var desc1781 = new ActionDescriptor();
  var id8700 = charIDToTypeID( "null" );
  var ref1346 = new ActionReference();
  var id8701 = charIDToTypeID( "Chnl" );
  var id8702 = charIDToTypeID( "fsel" );
  ref1346.putProperty( id8701, id8702 );
  desc1781.putReference( id8700, ref1346 );
  var id8703 = charIDToTypeID( "T   " );
  var desc1782 = new ActionDescriptor();
  var id8704 = charIDToTypeID( "Top " );
  var id8705 = charIDToTypeID( "#Pxl" );
  desc1782.putUnitDouble( id8704, id8705, top1 );
  var id8706 = charIDToTypeID( "Left" );
  var id8707 = charIDToTypeID( "#Pxl" );
  desc1782.putUnitDouble( id8706, id8707, left1 );
  var id8708 = charIDToTypeID( "Btom" );
  var id8709 = charIDToTypeID( "#Pxl" );
  desc1782.putUnitDouble( id8708, id8709, bottom1 );
  var id8710 = charIDToTypeID( "Rght" );
  var id8711 = charIDToTypeID( "#Pxl" );
  desc1782.putUnitDouble( id8710, id8711, right1 );
  var id8712 = charIDToTypeID( "Rctn" );
  desc1781.putObject( id8703, id8712, desc1782 );
  executeAction( id8699, desc1781, DialogModes.NO );

  // =======================================================
  var id8779 = charIDToTypeID( "AddT" );
  var desc1795 = new ActionDescriptor();
  var id8780 = charIDToTypeID( "null" );
  var ref1356 = new ActionReference();
  var id8781 = charIDToTypeID( "Chnl" );
  var id8782 = charIDToTypeID( "fsel" );
  ref1356.putProperty( id8781, id8782 );
  desc1795.putReference( id8780, ref1356 );
  var id8783 = charIDToTypeID( "T   " );
  var desc1796 = new ActionDescriptor();
  var id8784 = charIDToTypeID( "Top " );
  var id8785 = charIDToTypeID( "#Pxl" );
  desc1796.putUnitDouble( id8784, id8785, top2 );
  var id8786 = charIDToTypeID( "Left" );
  var id8787 = charIDToTypeID( "#Pxl" );
  desc1796.putUnitDouble( id8786, id8787, left2 );
  var id8788 = charIDToTypeID( "Btom" );
  var id8789 = charIDToTypeID( "#Pxl" );
  desc1796.putUnitDouble( id8788, id8789, bottom2 );
  var id8790 = charIDToTypeID( "Rght" );
  var id8791 = charIDToTypeID( "#Pxl" );
  desc1796.putUnitDouble( id8790, id8791, right2 );
  var id8792 = charIDToTypeID( "Rctn" );
  desc1795.putObject( id8783, id8792, desc1796 );
  executeAction( id8779, desc1795, DialogModes.NO );
}


function flipEm()
{
  //flip horixontal
  // =======================================================
  var id8811 = charIDToTypeID( "Flip" );
  var desc1800 = new ActionDescriptor();
  var id8812 = charIDToTypeID( "null" );
  var ref1359 = new ActionReference();
  var id8813 = charIDToTypeID( "Lyr " );
  var id8814 = charIDToTypeID( "Ordn" );
  var id8815 = charIDToTypeID( "Trgt" );
  ref1359.putEnumerated( id8813, id8814, id8815 );
  desc1800.putReference( id8812, ref1359 );
  var id8816 = charIDToTypeID( "Axis" );
  var id8817 = charIDToTypeID( "Ornt" );
  var id8818 = charIDToTypeID( "Hrzn" );
  desc1800.putEnumerated( id8816, id8817, id8818 );
  executeAction( id8811, desc1800, DialogModes.NO );
}