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

How to rotate image by transparent

New Here ,
Sep 01, 2022 Sep 01, 2022

Copy link to clipboard

Copied

Hi, I created an action that will automatically crop and clean around thousands of map images. But all of these maps are rotated (about 0.5 degrees, not the same in every picture). It would be enough if I rotated as much as the transparent part, but I couldn't do it anyway. I leave an example image. I'm sure it will be more understandable.

I use the crop and straighten action, but it sometimes crops important parts of the map. I just want to crop the transparent parts or straighten accordingly.

 

TOPICS
Actions and scripting , Windows

Views

805

Translate

Translate

Report

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
Adobe
Community Expert ,
Sep 01, 2022 Sep 01, 2022

Copy link to clipboard

Copied

Is this one of the images where Crop and Straighten Photos clips relevant parts? 

Votes

Translate

Translate

Report

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
New Here ,
Sep 01, 2022 Sep 01, 2022

Copy link to clipboard

Copied

No, this is the result after executing the action I recorded. Now I need to clean and fix the transparent parts, but I couldn't find a solution.

Votes

Translate

Translate

Report

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
Community Expert ,
Sep 01, 2022 Sep 01, 2022

Copy link to clipboard

Copied

Crop and Straighten Photos seems to work just fine on that image here. 

Please post images that actually illustrate the problem. 

Votes

Translate

Translate

Report

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
New Here ,
Sep 01, 2022 Sep 01, 2022

Copy link to clipboard

Copied

there are thousands of images, I noticed that this feature crops too much on some maps. I'll try again anyway, but how can I automatically apply this feature on multiple images? When I automate it, it saves the original image, not the result.

Votes

Translate

Translate

Report

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
Community Expert ,
Sep 01, 2022 Sep 01, 2022

Copy link to clipboard

Copied

I am pretty sure I have seen threads on Scripts to automate the saving of the resulting images of Crop and Straighten Photos. 

Please do a Forum search. 

 

To automate the task with a custom Script I expect you would need some Photoshop Scripting experience. 

Votes

Translate

Translate

Report

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
Community Expert ,
Sep 01, 2022 Sep 01, 2022

Copy link to clipboard

Copied

@Emrah252875449yv4 â€“ When you first posted back in July, I suggested that you check out the automated geometry correction features of the Camera Raw Filter, which can be scripted and then batch applied to PNG or PSD files. You didn't reply.

 

4options.png

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/jsx-gt-camera-raw-filter-gt-transform...

 

If these images were TIFF, JPEG or HEIC then you could batch apply directly using the Adobe Camera Raw plug-in.

 

Votes

Translate

Translate

Report

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
New Here ,
Sep 01, 2022 Sep 01, 2022

Copy link to clipboard

Copied

i forgot reply sorry. it didnt work

Votes

Translate

Translate

Report

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
Community Expert ,
Sep 02, 2022 Sep 02, 2022

Copy link to clipboard

Copied


@Emrah252875449yv4 wrote:

i forgot reply sorry. it didnt work


 

Do you mean that the script didn't work? Or do you mean that manually running one of the four options in the Camera Raw Filter didn't produce an acceptable result?

Votes

Translate

Translate

Report

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
New Here ,
Sep 02, 2022 Sep 02, 2022

Copy link to clipboard

Copied

JSX file and CameraRaw filter do not give the expected result. It just turns its rotation in a different direction, but this is not the expected result.

Votes

Translate

Translate

Report

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
Advocate ,
Sep 02, 2022 Sep 02, 2022

Copy link to clipboard

Copied

Why don't you just share some original files (a few that work and a few that don't) so we can try a few things?

Votes

Translate

Translate

Report

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
New Here ,
Sep 02, 2022 Sep 02, 2022

Copy link to clipboard

Copied

I already shared the final version of the file. But if you want the original, I'll share that too. Some not working is not a big problem for me. However, I couldn't find a way to do the last step properly.

Votes

Translate

Translate

Report

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
New Here ,
Sep 02, 2022 Sep 02, 2022

Copy link to clipboard

Copied

 

also i will share my actions file. you can delete .png extension for using

Votes

Translate

Translate

Report

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
New Here ,
Sep 02, 2022 Sep 02, 2022

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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
People's Champ ,
Sep 02, 2022 Sep 02, 2022

Copy link to clipboard

Copied

Specifically for the file linked in the first post.

 

1.

Increase the canvas size by 5%. Execute the "crop & straighten" command.

 

2.

You can also make a copy under the first layer turned into a smart object. Also increase the canvas size so that there is more transparency around. Standing on the original (top) layer, do "crop & straighten". Then you can do a "reveal all" to reveal possibly hidden details outside of the canvas.

Votes

Translate

Translate

Report

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
Community Expert ,
Sep 03, 2022 Sep 03, 2022

Copy link to clipboard

Copied

LATEST

I recently looked into something else that concerned rectangles in Photoshop and parts of that could maybe be applied here. 

With the supplied image it seems to work, but I expect the worse the layers’ edges the less the result would be meaningful. 

// rotate active layer if it is roughly rectangular;
// 2022, use it at your own risk;
if (app.documents.length > 0) {
var myDocument = activeDocument;
loadTransparency(false);
makeWorkPath (3);
var thisPath = collectPathInfoFromDesc2012 (myDocument, myDocument.pathItems[myDocument.pathItems.length-1]);
// work through supathitems;
for (var a = 0; a < thisPath.length; a++) {
var thisOne = thisPath[a];
var thePoints = new Array;
var theAngles = new Array;
var theDistances = new Array;
for (var m = 0; m < thisOne.length-2; m++) {
    if (m == 0) {var thePrevious = thisOne.length-3} 
    else {var thePrevious = m-1};
    if (m == thisOne.length-3) {var theNext = 0} 
    else {var theNext = m+1};
    theDistances.push(getDistance(thisOne[m][0], thisOne[thePrevious][0]));
    theAngles.push(getAngle (thisOne[m][0], thisOne[theNext][0]));
    thePoints.push(thisOne[m][0]);
    };
// try to remove extra points;
var theAngleVar = 4;
var theResults = [thePoints[0]];
var theAngle = theAngles[0];
for (var n = 0; n < theAngles.length; n++) {
    var nextAngle = theAngles[n];
    if (absAngleDiff (theAngle, nextAngle) < theAngleVar) {}
    else {
        if (theDistances[n] > 5) {
            theAngle = nextAngle;
            theResults.push(thePoints[n])
        }
    };
};
// create path array;
var anArray = [[]];
for (var x = 0; x < theResults.length; x++) {
    anArray[0].push([theResults[x], theResults[x], theResults[x], false])
};
// check for four points;
if (anArray[0].length == 4) {
// check the four angles;
var angle1 = getAngle(anArray[0][0][0], anArray[0][1][0]);
var angle2 = getAngle(anArray[0][1][0], anArray[0][2][0]);
var angle3 = getAngle(anArray[0][2][0], anArray[0][3][0]);
var angle4 = getAngle(anArray[0][3][0], anArray[0][0][0]);
if (absAngleDiff(angle1, angleLimit (angle3+180)) < 2 && absAngleDiff(angle1, angleLimit (angle2-90)) < 2 && absAngleDiff(angle1, angleLimit (angle4+90)) < 2) {
anArray[0].push(true);
anArray[0].push(1737);
}
} else {alert (a+" doesn't work out")}
};
if (anArray.length == 1) {
    convertToSmartObject ();
    var theID = getLayerId();
    duplicateMoveRotateScale (theID, 0, 0, 100, 100, (90-angle1), false);
}
};
////////////////////////////////////
////// collect path info from actiondescriptor, smooth added //////
function collectPathInfoFromDesc2012 (myDocument, thePath) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
// based of functions from xbytor’s stdlib;
var idPath = charIDToTypeID( "Path" );
var ref = new ActionReference();
for (var l = 0; l < myDocument.pathItems.length; l++) {
    var thisPath = myDocument.pathItems[l];
    if (thisPath == thePath && thisPath.kind == PathKind.WORKPATH) {
        ref.putProperty(idPath, cTID("WrPt"));
        };
    if (thisPath == thePath && thisPath.kind != PathKind.WORKPATH && thisPath.kind != PathKind.VECTORMASK) {
        ref.putIndex(idPath, l + 1);
        };
    if (thisPath == thePath && thisPath.kind == PathKind.VECTORMASK) {
        var idvectorMask = stringIDToTypeID( "vectorMask" );
        ref.putEnumerated( idPath, idPath, idvectorMask );
        };
    };
var desc = app.executeActionGet(ref);
var pname = desc.getString(cTID('PthN'));
// create new array;
var theArray = new Array;
var pathComponents = desc.getObjectValue(cTID("PthC")).getList(sTID('pathComponents'));
// for subpathitems;
for (var m = 0; m < pathComponents.count; m++) {
    var listKey = pathComponents.getObjectValue(m).getList(sTID("subpathListKey"));
    var operation1 = pathComponents.getObjectValue(m).getEnumerationValue(sTID("shapeOperation"));
    switch (operation1) {
        case 1097098272:
        var operation = 1097098272 //cTID('Add ');
        break;
        case 1398961266:
        var operation = 1398961266 //cTID('Sbtr');
        break;
        case 1231975538:
        var operation = 1231975538 //cTID('Intr');
        break;
        default:
//		case 1102:
        var operation = sTID('xor') //ShapeOperation.SHAPEXOR;
        break;
        };
// for subpathitem’s count;
    for (var n = 0; n < listKey.count; n++) {
        theArray.push(new Array);
        var points = listKey.getObjectValue(n).getList(sTID('points'));
        try {var closed = listKey.getObjectValue(n).getBoolean(sTID("closedSubpath"))}
        catch (e) {var closed = false};
// for subpathitem’s segment’s number of points;
        for (var o = 0; o < points.count; o++) {
            var anchorObj = points.getObjectValue(o).getObjectValue(sTID("anchor"));
            var anchor = [anchorObj.getUnitDoubleValue(sTID('horizontal')), anchorObj.getUnitDoubleValue(sTID('vertical'))];
            var thisPoint = [anchor];
            try {
                var left = points.getObjectValue(o).getObjectValue(cTID("Fwd "));
                var leftDirection = [left.getUnitDoubleValue(sTID('horizontal')), left.getUnitDoubleValue(sTID('vertical'))];
                thisPoint.push(leftDirection)
                }
            catch (e) {
                thisPoint.push(anchor)
                };
            try {
                var right = points.getObjectValue(o).getObjectValue(cTID("Bwd "));
                var rightDirection = [right.getUnitDoubleValue(sTID('horizontal')), right.getUnitDoubleValue(sTID('vertical'))];
                thisPoint.push(rightDirection)
                }
            catch (e) {
                thisPoint.push(anchor)
                };
            try {
                var smoothOr = points.getObjectValue(o).getBoolean(cTID("Smoo"));
                thisPoint.push(smoothOr)
                }
            catch (e) {thisPoint.push(false)};
            theArray[theArray.length - 1].push(thisPoint);
            };
        theArray[theArray.length - 1].push(closed);
        theArray[theArray.length - 1].push(operation);
        };
    };
// by xbytor, thanks to him;
function cTID (s) { return cTID[s] || cTID[s] = app.charIDToTypeID(s); };
function sTID (s) { return sTID[s] || sTID[s] = app.stringIDToTypeID(s); };
// reset;
app.preferences.rulerUnits = originalRulerUnits;
return theArray;
};
////// radians //////
function radiansOf (theAngle) {
    return theAngle * Math.PI / 180
};
////// get an angle, 3:00 being 0Ëš, 6:00 90Ëš, etc. //////
function getAngle (pointOne, pointTwo) {
// calculate the triangle sides;
var width = pointTwo[0] - pointOne[0];
var height = pointTwo[1] - pointOne[1];
var sideC = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)); 
// calculate the angles;
if (width+width > width) {theAngle = Math.asin(height / sideC) * 360 / 2 / Math.PI}
else {theAngle = 180 - (Math.asin(height / sideC) * 360 / 2 / Math.PI)};
if (theAngle < 0) {theAngle = (360 + theAngle)};
//	if (theAngle > 180) {theAngle = (360 - theAngle) * (-1)};
return theAngle
};
////// get a distance between two points //////
function getDistance (pointOne, pointTwo) {
// calculate the triangle sides;
var width = pointTwo[0] - pointOne[0];
var height = pointTwo[1] - pointOne[1];
var sideC = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)); 
return sideC
};
////// make work path from selection //////
function makeWorkPath (theTolerance) {
// =======================================================
var idMk = charIDToTypeID( "Mk  " );
    var desc5 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref3 = new ActionReference();
        var idPath = charIDToTypeID( "Path" );
        ref3.putClass( idPath );
    desc5.putReference( idnull, ref3 );
    var idFrom = charIDToTypeID( "From" );
        var ref4 = new ActionReference();
        var idcsel = charIDToTypeID( "csel" );
        var idfsel = charIDToTypeID( "fsel" );
        ref4.putProperty( idcsel, idfsel );
    desc5.putReference( idFrom, ref4 );
    var idTlrn = charIDToTypeID( "Tlrn" );
    var idPxl = charIDToTypeID( "#Pxl" );
    desc5.putUnitDouble( idTlrn, idPxl, theTolerance );
executeAction( idMk, desc5, DialogModes.NO );
};
////// load transparency //////
function loadTransparency (theInvert) {
    var desc3 = new ActionDescriptor();
        var ref2 = new ActionReference();
        ref2.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
    desc3.putReference( charIDToTypeID( "null" ), ref2 );
        var ref3 = new ActionReference();
        ref3.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Trsp" ) );
    desc3.putReference( charIDToTypeID( "T   " ), ref3 );
    desc3.putBoolean(charIDToTypeID("Invr"), theInvert);
executeAction( charIDToTypeID( "setd" ), desc3, DialogModes.NO );
};
////// get absolute number of angle difference //////
function absAngleDiff (theAngle, nextAngle) {
return Math.min(Math.abs((Math.max(theAngle, nextAngle)-Math.min(theAngle, nextAngle))),
Math.abs(Math.max(theAngle, nextAngle)-(Math.min(theAngle, nextAngle)+360)))
};
////// convert to smart object //////
function convertToSmartObject () {
var desc108 = new ActionDescriptor();
var ref77 = new ActionReference();
ref77.putEnumerated( charIDToTypeID( "Mn  " ), charIDToTypeID( "MnIt" ), stringIDToTypeID( "newPlacedLayer" ) );
desc108.putReference( charIDToTypeID( "null" ), ref77 );
executeAction( charIDToTypeID( "slct" ), desc108, DialogModes.NO );
};
// by mike hale, via paul riggott;
function getLayerId(){
    // http://forums.adobe.com/message/1944754#1944754
        var ref = new ActionReference(); 
        ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt")); 
        d = executeActionGet(ref); 
    return d.getInteger(charIDToTypeID('LyrI')); 
    };
////// based on code by mike hale and paul riggott //////
function selectLayerByID(index,add){ 
    add = undefined ? add = false:add 
    var ref = new ActionReference();
        ref.putIdentifier(charIDToTypeID("Lyr "), index);
        var desc = new ActionDescriptor();
        desc.putReference(charIDToTypeID("null"), ref );
            if(add) desc.putEnumerated( stringIDToTypeID( "selectionModifier" ), stringIDToTypeID( "selectionModifierType" ), stringIDToTypeID( "addToSelection" ) ); 
            desc.putBoolean( charIDToTypeID( "MkVs" ), false ); 
        try{
        executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
    }catch(e){
    alert(e.message); 
    }
    };
////// duplicate layer and move, rotate and scale it //////
function duplicateMoveRotateScale (theID, theX, theY, theScaleX, theScaleY, theRotation, theCopy) {
    selectLayerByID(theID,false);
    try{
    var idTrnf = charIDToTypeID( "Trnf" );
        var desc10 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref6 = new ActionReference();
            ref6.putIdentifier( charIDToTypeID( "Lyr " ), theID );
        desc10.putReference( idnull, ref6 );
        var idFTcs = charIDToTypeID( "FTcs" );
        var idQCSt = charIDToTypeID( "QCSt" );
        var idQcsa = charIDToTypeID( "Qcsa" );
        desc10.putEnumerated( idFTcs, idQCSt, idQcsa );
        var idOfst = charIDToTypeID( "Ofst" );
            var desc11 = new ActionDescriptor();
            var idHrzn = charIDToTypeID( "Hrzn" );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc11.putUnitDouble( idHrzn, idPxl, theX );
            var idVrtc = charIDToTypeID( "Vrtc" );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc11.putUnitDouble( idVrtc, idPxl, theY );
        var idOfst = charIDToTypeID( "Ofst" );
        desc10.putObject( idOfst, idOfst, desc11 );
        var idWdth = charIDToTypeID( "Wdth" );
        var idPrc = charIDToTypeID( "#Prc" );
        desc10.putUnitDouble( idWdth, idPrc, theScaleX );
        var idHght = charIDToTypeID( "Hght" );
        var idPrc = charIDToTypeID( "#Prc" );
        desc10.putUnitDouble( idHght, idPrc, theScaleY );
        var idAngl = charIDToTypeID( "Angl" );
        var idAng = charIDToTypeID( "#Ang" );
        desc10.putUnitDouble( idAngl, idAng, theRotation );
        var idIntr = charIDToTypeID( "Intr" );
        var idIntp = charIDToTypeID( "Intp" );
        var idbicubicAutomatic = stringIDToTypeID( "bicubicAutomatic" );
        desc10.putEnumerated( idIntr, idIntp, idbicubicAutomatic );
        var idCpy = charIDToTypeID( "Cpy " );
        desc10.putBoolean( idCpy, theCopy );
    executeAction( idTrnf, desc10, DialogModes.NO );
    var thisCopy = app.activeDocument.activeLayer;
    return thisCopy
    } catch (e) {}
    };
//////
function angleLimit (theAngle) {
    while (theAngle > 360) {theAngle = theAngle - 360};
    while (theAngle < 360) {theAngle = theAngle + 360};
    return theAngle
};

Screenshot 2022-09-03 at 15.25.10.pngScreenshot 2022-09-03 at 15.25.00.png 

Votes

Translate

Translate

Report

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