質問

I am quite new to Photoshop scripts, and I want to do the following:

Transform images in batch, for each image, swap a piece like this*,

 _____________________
|                     |
|                     |
|                     |
|______         ______|
|      |       |      |
|  9   |       |   E  |
|______|       |______|
|                     |
|                     |
|                     |
|                     |
|                     |
|_____________________|

become this:

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

I just want to know how can I do it, which functions and so on. About the position, I can't say which pixels exactly, so, Just give me an example and I calculate the number I must use

  • Considering that 3 is similar to the horizontal flip of E and same thing with e to 9
役に立ちましたか?

解決

Here is the script that will do the job. Most of it was written using the script listener And yup, the script listener code looks horrible, but after a while you can put snipets of the script listener code and turn them into functions. Which is what I've done. You didn't specify how big the image was so this script works on one that is 100 pixels by 100 pixels and will flip the selected layer. The magic numbers which specify the co-ordinates are used tin the select this line of code. Change that for your own needs.

If you are interested in learning how to code for photoshop then I suggest you use (and learn) javaScript. Oh and have a look at the script listener. Have fun.

//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 );
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top