Skip to main content
Participant
June 6, 2019
Question

how to mirror an image horizantaly?

  • June 6, 2019
  • 2 replies
  • 375 views

i want either to mirror the image left to right or right to left from canvas center or to crop flip horizantaly. has to be done entirely by code. problem is when you flip horiztnaly it offsets the image and you have to manully place it. and ther eis no fixed ammount of pixels for this movement. any ideas how to get this done?

i have:

var doc = app.activeDocument;

// =======================================================

var idslct = charIDToTypeID( "slct" );

    var desc48 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref40 = new ActionReference();

        var idmarqueeRectTool = stringIDToTypeID( "marqueeRectTool" );

        ref40.putClass( idmarqueeRectTool );

    desc48.putReference( idnull, ref40 );

    var iddontRecord = stringIDToTypeID( "dontRecord" );

    desc48.putBoolean( iddontRecord, true );

    var idforceNotify = stringIDToTypeID( "forceNotify" );

    desc48.putBoolean( idforceNotify, true );

executeAction( idslct, desc48, DialogModes.NO );

// =======================================================

var idsetd = charIDToTypeID( "setd" );

    var desc49 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref41 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idfsel = charIDToTypeID( "fsel" );

        ref41.putProperty( idChnl, idfsel );

    desc49.putReference( idnull, ref41 );

    var idT = charIDToTypeID( "T   " );

        var desc50 = new ActionDescriptor();

        var idTop = charIDToTypeID( "Top " );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc50.putUnitDouble( idTop, idPxl, 0.000000 );

        var idLeft = charIDToTypeID( "Left" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc50.putUnitDouble( idLeft, idPxl, 0.000000 );

        var idBtom = charIDToTypeID( "Btom" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc50.putUnitDouble( idBtom, idPxl, doc.height.value );

        var idRght = charIDToTypeID( "Rght" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc50.putUnitDouble( idRght, idPxl, doc.width.value/2 );

    var idRctn = charIDToTypeID( "Rctn" );

    desc49.putObject( idT, idRctn, desc50 );

executeAction( idsetd, desc49, DialogModes.NO );

// =======================================================

var idDlt = charIDToTypeID( "Dlt " );

executeAction( idDlt, undefined, DialogModes.NO );

// =======================================================

var idsetd = charIDToTypeID( "setd" );

    var desc51 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref42 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idfsel = charIDToTypeID( "fsel" );

        ref42.putProperty( idChnl, idfsel );

    desc51.putReference( idnull, ref42 );

    var idT = charIDToTypeID( "T   " );

    var idOrdn = charIDToTypeID( "Ordn" );

    var idNone = charIDToTypeID( "None" );

    desc51.putEnumerated( idT, idOrdn, idNone );

executeAction( idsetd, desc51, DialogModes.NO );

This topic has been closed for replies.

2 replies

Participant
June 9, 2019

thank you for the response. i couldnt quite figure how to get your code to work. what do you put in position and in method?

JJMack
Community Expert
Community Expert
June 9, 2019

The code is action manager code for menu Layer>align Layers to selection.  You make a selection like select al or just a single pixel. Toy can the target layers and align the layer to the  selection. 9 possible alignments are possible. 3x3=9  3 horizontal 3 vertical alignments

Translate is Doe code the movement is relative to the layer current location +-x +-y pixels only x or y is requited either is optional.

JJMack
JJMack
Community Expert
Community Expert
June 6, 2019

Flipping an image  horizontally reverses the image it does not mirror the image.  You can move a layer content  relativly with  translate and you can align a layer to a selection. Layer bounds will get the current location and width and height. Align to a selection requires action manager code. Soem image flipped will look quit convincing as a mirrored image A lot depends on the perspectiv apearencs of the image conten.

switch (Position){

case 1 : align('AdLf'); align('AdTp'); break;

case 2 : align('AdCH'); align('AdTp'); break;

case 3 : align('AdRg'); align('AdTp'); break;

case 4 : align('AdLf'); align('AdCV'); break;

case 5 : align('AdCH'); align('AdCV'); break;

case 6 : align('AdRg'); align('AdCV'); break;

case 7 : align('AdLf'); align('AdBt'); break;

case 8 : align('AdCH'); align('AdBt'); break;

case 9 : align('AdRg'); align('AdBt'); break;

default : break;

}

function align(method) {

   var desc = new ActionDescriptor();

   var ref = new ActionReference();

   ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

   desc.putReference( charIDToTypeID( "null" ), ref );

   desc.putEnumerated( charIDToTypeID( "Usng" ), charIDToTypeID( "ADSt" ), charIDToTypeID( method ) );

   try{

      executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );

   }catch(e){}

}

JJMack