Skip to main content
AG_Ps_100
Inspiring
September 15, 2018
Answered

Make Rectangle from Trapezoid

  • September 15, 2018
  • 4 replies
  • 17148 views

Hello everyone,

I have a trapezoid and i want to turn it to rectangle by using script.

it is basically something like this:

BEFORE

AFTER

i need to find the width of the small side of the trapezoid, in our case it's 2043px:

and after the transform the other side will be 2043 as well:

any ideas?

This topic has been closed for replies.
Correct answer r-bin

created a WorkPath, i'm getting this:

I wonder if it's possible to make it work without having to create a work path because the script straightens any quadrangle to rectangle did not require a work path, and the script Auto Symmetry Skew did not require a work path. a combination of the two can be pretty awesome


strai3.jsxbin - Google Drive

4 replies

Participant
May 11, 2021

Hello I have same problem. I have a trapezoid picture and i want convert it to rectangel, would you please share the solution with me?

 

 

AG_Ps_100
AG_Ps_100Author
Inspiring
January 30, 2019

r-bin​ I've noticed we solved these two issues in this thread:

1. Straightening Trapezoid

example:

BEFORE

AFTER

2. Straightens any quadrangle to rectangle

example:

BEFORE

AFTER

How can I solve my initial problem which is turning trapezoid to rectangle but keeping on original X1 and X2

(X1 and X2 being the coordinates of the top side of the trapezoid)

BEFORE

AFTER

any help?

Legend
February 1, 2019

All this is unnecessary nonsense.

strai4.jsxbin - Google Drive

AG_Ps_100
AG_Ps_100Author
Inspiring
February 1, 2019

it worked always helpful.

why "All this is unnecessary nonsense." though?

AG_Ps_100
AG_Ps_100Author
Inspiring
September 23, 2018

any chance to bother you to combine the two?

this is the auto symmetry one:

  1. app.activeDocument.suspendHistory("Skew","skew_straighten_layer()");   
  2.    
  3. function skew_straighten_layer()   
  4.     {   
  5.     try {    
  6.         app.preferences.rulerUnits = Units.PIXELS;   
  7.  
  8.         var doc = app.activeDocument;   
  9.         var layer = app.activeDocument.activeLayer;   
  10.  
  11.         selection_from_layer();   
  12.  
  13.         var dh = Number(layer.bounds[3].value - layer.bounds[1].value)*0.01; 
  14.    
  15.         select_single_line(Number(layer.bounds[1].value) + dh, true, stringIDToTypeID("intersectWith"));   
  16.  
  17.         var x0 = Number(doc.selection.bounds[2].value + doc.selection.bounds[0].value)/2; 
  18.         var y0 = Number(doc.selection.bounds[3].value); 
  19.  
  20.         selection_from_layer();   
  21.  
  22.         select_single_line(Number(layer.bounds[3].value) - dh, true, stringIDToTypeID("intersectWith"));   
  23.  
  24.         var x1 = Number(doc.selection.bounds[2].value + doc.selection.bounds[0].value)/2; 
  25.         var y1 = Number(doc.selection.bounds[3].value); 
  26.  
  27.         doc.selection.deselect();     
  28.  
  29.         var w = x1 - x0;   
  30.         var h = y1 - y0;   
  31.    
  32.         var angle;   
  33.         if (h != 0)  
  34.             { 
  35.             angle = Math.atan(w/h) * 180.0 / Math.PI;   
  36.  
  37.             skew(layer, -angle,0, x1, y1); 
  38.             } 
  39.         }   
  40.     catch (e) { alert(e) }   
  41.     }   
  42.    
  43. function select_single_line(x, h, mode)   
  44.     {   
  45.     try   
  46.         {   
  47.         if (mode == undefined) mode = stringIDToTypeID("set");   
  48.    
  49.         var r = new ActionReference();   
  50.         r.putProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));   
  51.    
  52.         var d = new ActionDescriptor();   
  53.         d.putReference(stringIDToTypeID("target"), r);   
  54.    
  55.         var d1 = new ActionDescriptor();   
  56.         d1.putUnitDouble(stringIDToTypeID(h?"top":"left"), stringIDToTypeID("pixelsUnit"), x);   
  57.    
  58.         d.putObject(stringIDToTypeID("to"), stringIDToTypeID(h?"singleRow":"singleColumn"), d1);   
  59.    
  60.         executeAction(mode, d, DialogModes.NO);   
  61.         }   
  62.     catch (e) { throw(e); }   
  63.     }   
  64.    
  65. function selection_from_layer()   
  66.     {   
  67.     try   
  68.         {   
  69.         var r = new ActionReference();   
  70.         r.putProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));   
  71.    
  72.         var d = new ActionDescriptor();   
  73.         d.putReference(stringIDToTypeID("target"), r);   
  74.    
  75.         var r = new ActionReference();   
  76.         r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("transparencyEnum"));   
  77.         d.putReference(stringIDToTypeID("to"), r);   
  78.    
  79.         executeAction(stringIDToTypeID("set"), d, DialogModes.NO);   
  80.         }   
  81.     catch (e) { throw(e); }   
  82.     }   
  83.  
  84. function skew(layer, h,v, x, y) 
  85.     { 
  86.     try 
  87.         { 
  88.         app.activeDocument.activeLayer = layer; 
  89.  
  90.         var d1 = new ActionDescriptor(); 
  91.         var d2 = new ActionDescriptor(); 
  92.         var d3 = new ActionDescriptor(); 
  93.         var d4 = new ActionDescriptor(); 
  94.         var r1 = new ActionReference(); 
  95.  
  96.         r1.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) ); 
  97.  
  98.         d1.putReference( charIDToTypeID( "null" ), r1 ); 
  99.  
  100.         d1.putEnumerated( charIDToTypeID( "FTcs" ), charIDToTypeID( "QCSt" ), charIDToTypeID( "Qcsi" ) ); 
  101.  
  102.         if (x != undefined &&  y != undefined) 
  103.             {    
  104.             d2.putUnitDouble( charIDToTypeID( "Hrzn" ), charIDToTypeID( "#Pxl" ), x ); 
  105.             d2.putUnitDouble( charIDToTypeID( "Vrtc" ), charIDToTypeID( "#Pxl" ), y ); 
  106.             d1.putObject( charIDToTypeID( "Pstn" ), charIDToTypeID( "Pnt " ), d2 ); 
  107.             } 
  108.  
  109.         d4.putUnitDouble( charIDToTypeID( "Hrzn" ), charIDToTypeID( "#Ang" ), h ); 
  110.         d4.putUnitDouble( charIDToTypeID( "Vrtc" ), charIDToTypeID( "#Ang" ), v ); 
  111.  
  112.         d1.putObject( charIDToTypeID( "Skew" ), charIDToTypeID( "Pnt " ), d4 ); 
  113.  
  114.         executeAction( charIDToTypeID( "Trnf" ), d1, DialogModes.NO ); 
  115.         } 
  116.     catch (e) { throw(e); }   
  117.     } 

and combine it with the jsxbin of this thread.

thanks anyway!

Legend
September 23, 2018

Mark as accurately as possible corners with four WorkPath points in the sequence as described in post # 6.

Run the script strai2.jsxbin - Google Drive

AG_Ps_100
AG_Ps_100Author
Inspiring
September 26, 2018

created a WorkPath, i'm getting this:

I wonder if it's possible to make it work without having to create a work path because the script straightens any quadrangle to rectangle did not require a work path, and the script Auto Symmetry Skew did not require a work path. a combination of the two can be pretty awesome

Legend
September 15, 2018

Try it.

Straightens any quadrangle to rectangle.

eval("@JSXBIN@ES@2.0@MyBbyBnAHMgfbyBn0ABghBbyBn0ALOhCJhDnAEjzNjFjYjFjDjVjUjFiBjDjUjJjP"+

"jOBfRDEjzQjTjUjSjJjOjHiJiEiUjPiUjZjQjFiJiECfRBFeOjOjFjXiQjMjBjDjFjEiMjBjZjFjSff"+

"jzJjVjOjEjFjGjJjOjFjEDfXzCiOiPEfjzLiEjJjBjMjPjHiNjPjEjFjTFfffACzChBhdGXzEjLjJjO"+

"jEHfXzLjBjDjUjJjWjFiMjBjZjFjSIfXzOjBjDjUjJjWjFiEjPjDjVjNjFjOjUJfjzDjBjQjQKfXzLi"+

"TiNiBiSiUiPiCiKiFiDiULfjzJiMjBjZjFjSiLjJjOjEMfnnnJhFnASzFjMjBjZjFjSNAXIfXJfjKfn"+

"ftJhHnAEjzHjSjFjGjSjFjTjIOfnfJhInAEjzMjTjJjEjFifjEjJjTjUjPjSjUPfRCVNfAFdAffJhJn"+

"AEjOfnfJhKnAEjPfRCVNfAFdCffJhLnAEjOfnfJhMnAEjPfRCVNfAFdBffJhNnAEjOfnfJhOnAEjPfR"+

"CVNfAFdDffJhQnAEXzIjEjFjTjFjMjFjDjUQfXzJjTjFjMjFjDjUjJjPjORfXJfjKfnfABnzBjFSnby"+

"Bn0ACJhSnAEXQfXRfXJfjKfnfJyhSnABjzCjPjLTfncffABN40BiAABAzEjNjBjJjOUAhTMhWbyBn0A"+

"BghYbyBn0AMJhZnASzBjQVAEjzFiBjSjSjBjZWfntnftchdnAVzEjTjJjEjFXfHFRBFdAfRBFdBfRBF"+

"dCfRBFdDfRBnfFbiAn0AEJiAnABXzBhQYfVVfAEjzJjHjFjUifjQjPjJjOjUZfRCVNfGFdAffnfJiBn"+

"ABXzBhRgafVVfAEjZfRCVNfGFdDffnfJiCnASzDjWjFjSgbBncfffDiDnAzAgctbiGn0AEJiGnABXYf"+

"VVfAEjZfRCVNfGFdBffnfJiHnABXgafVVfAEjZfRCVNfGFdAffnfJiInASgbBnctffDiJnAgctbiMn0"+

"AEJiMnABXYfVVfAEjZfRCVNfGFdCffnfJiNnABXgafVVfAEjZfRCVNfGFdBffnfJiOnASgbBncfffDi"+

"PnAgctbiSn0AEJiSnABXYfVVfAEjZfRCVNfGFdDffnfJiTnABXgafVVfAEjZfRCVNfGFdCffnfJiUnA"+

"SgbBnctffDiVnAgctbyiYn0ABZiYnAnJibnASzDjBjOjHgdCndAftJicnASzDjJjOjWgeDncfftJien"+

"ASzBjXgfECzBhNhAXYfXYfVVfAXYfXgafVVfAnnnftJifnASzBjIhBFChAXgafXYfVVfAXgafXgafVV"+

"fAnnnftOjBbyjDn0ABOjDJjDnASgdCCzBhPhCCzBhKhDEXzEjBjUjBjOhEfjzEiNjBjUjIhFfRBChCV"+

"gffEVhBfFnnffnndlUXzCiQiJhGfjhFfnnnffACGVhBfFnndAnAhzBhBhHVgbfBbyjHn0ABOjHJjHnA"+

"SgdCChCChDhzBhNhIEXhEfjhFfRBChCVhBfFVgffEnnffnndlUXhGfjhFfnnnffACGVgffEnndAnOjK"+

"bjMn0ACJjMnAEXQfXRfXJfjKfnfZjNnAFctAhhHVgdfCnOjQbyjSn0ABOjSbjUn0ADJjUnASgeDnctf"+

"fJjWnABjzBjYhJfXYfXgafVVfAnfJjXnABjzBjZhKfXgafXgafVVfAnfACzBhchLXYfXgafVVfAXYfX"+

"YfVVfAnnbjbn0ACJjbnABjhJfXYfXYfVVfAnfJjcnABjhKfXgafXYfVVfAnfAhhHVgbfBbykBn0ABOk"+

"BbkDn0ACJkDnABjhJfXYfXgafVVfAnfJkEnABjhKfXgafXgafVVfAnfAChLXgafXgafVVfAXgafXYfV"+

"VfAnnbkIn0ADJkInASgeDnctffJkKnABjhJfXYfXYfVVfAnfJkLnABjhKfXgafXYfVVfAnfJkPnAEXQ"+

"fXRfXJfjKfnfJkRnAEjzHjEjJjTjUjPjSjUhMfRGVNfGVgdfCVgbfBVgefDjhJfjhKfffZkTnAFctAB"+

"nSnbyBn0ABfkVnAjSfAIhB4F0AiAgf4E0AiAV40BiAN40BhAX4B0AhAgb4B0AiAgd4C0AiAge4D0AiA"+

"CGAPAkWMkZbyBn0ABgkbbyBn0ALJkcnABXzKjSjVjMjFjSiVjOjJjUjThNfXzLjQjSjFjGjFjSjFjOj"+

"DjFjThOfjKfXzGiQiJiYiFiMiThPfjzFiVjOjJjUjThQfnfJkenASzBjChRAXzGjCjPjVjOjEjThSfV"+

"NfKnftJlKnASgfDEjzGiOjVjNjCjFjShTfRBChAXzFjWjBjMjVjFhUfXzBhShVfVhRfAXhUfXYfVhRf"+

"AnnffnftJlLnAShBEEjhTfRBChAXhUfXzBhThWfVhRfAXhUfXgafVhRfAnnffnftOlNblPn0AFJlPnA"+

"ShJBEjhTfRBXhUfXYfVhRfAffnffJlQnAShKCEjhTfRBXhUfXgafVhRfAffnffJlSnASzEjTjUjFjQh"+

"XFVgffDnffJlUnASzGjTjJjHjOifjYhYGndBffJlVnASzGjTjJjHjOifjZhZHndBffACzChdhdhaVzF"+

"jQjPjJjOjUhbfLnndAnOlYblan0AFJlanAShJBEjhTfRBXhUfXhVfVhRfAffnffJlbnAShKCEjhTfRB"+

"XhUfXgafVhRfAffnffJldnAShXFVgffDnffJlfnAShYGndyBffJmAnAShZHndBffAChaVhbfLnndBnO"+

"mDbmFn0AFJmFnAShJBEjhTfRBXhUfXhVfVhRfAffnffJmGnAShKCEjhTfRBXhUfXhWfVhRfAffnffJm"+

"InAShXFVgffDnffJmKnAShYGndyBffJmLnAShZHndyBffAChaVhbfLnndCnOmObmQn0AHJmQnAShJBE"+

"jhTfRBXhUfXYfVhRfAffnffJmRnAShKCEjhTfRBXhUfXhWfVhRfAffnffJmTnASgfDEjhTfRBChAX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hJfQnnnnnnnffJ2iMBnASiXJChAViUfGViWfInnnffO2iSBby2iUBn0AB"+

"O2iUBb2iWBn0ACO2iWBJ2iWBnASzCjShQiZKAREViVfHViUfGViRfDViWfIfnffAhhHVgefPJ2iXBnA"+

"SiZKAREViSfFViUfGViRfDViWfIfnffO2iZBJ2iZBnASzCjOhQiaLAREARCXYfViZfKXgafViZfKfAR"+

"CXhVfViZfKXgafViZfKfARCXhVfViZfKXhWfViZfKfARCChdXYfViZfKViXfJnnXhWfViZfKffnffAh"+

"hHVgefPJ2iaBnASiaLAREARCChAXYfViZfKViXfJnnXgafViZfKfARCXhVfViZfKXgafViZfKfARCXh"+

"VfViZfKXhWfViZfKfARCXYfViZfKXhWfViZfKffnffAChLEXzDjBjCjTibfjhFfRBChAViSfFViGfBn"+

"nffEXibfjhFfRBChAViSfFViRfDnnffnnb2ieBn0ACO2ieBJ2ieBnASiZKAREViGfBViUfGViVfHViW"+

"fIfnffAhhHVgefPJ2ifBnASiZKAREViGfBViUfGViSfFViWfIfnffO2jBBJ2jBBnASiaLAREARCXYfV"+

"iZfKXgafViZfKfARCXhVfViZfKXgafViZfKfARCChdXhVfViZfKViXfJnnXhWfViZfKfARCXYfViZfK"+

"XhWfViZfKffnffAhhHVgefPJ2jCBnASiaLAREARCXYfViZfKXgafViZfKfARCChAXhVfViZfKViXfJn"+

"nXgafViZfKfARCXhVfViZfKXhWfViZfKfARCXYfViZfKXhWfViZfKffnffAhhHViYfOby2jHBn0ABO2"+

"jHBb2jJBn0ACO2jJBJ2jJBnASiZKAREViSfFViQfCViVfHViWfIfnffAhhHVgefPJ2jKBnASiZKAREV"+

"iSfFViQfCViVfHViUfGfnffO2jMBJ2jMBnASiaLAREARCXYfViZfKXgafViZfKfARCXhVfViZfKXgaf"+

"ViZfKfARCXhVfViZfKChdXhWfViZfKViXfJnnfARCXYfViZfKXhWfViZfKffnffAhhHVgefPJ2jNBnA"+

"SiaLAREARCXYfViZfKXgafViZfKfARCXhVfViZfKXgafViZfKfARCXhVfViZfKXhWfViZfKfARCXYfV"+

"iZfKChAXhWfViZfKViXfJnnffnffAChLEXibfjhFfRBChAViUfGVhRfEnnffEXibfjhFfRBChAViUfG"+

"ViQfCnnffnnb2jRBn0ACO2jRBJ2jRBnASiZKAREViSfFViWfIViVfHVhRfEfnffAhhHVgefPJ2jSBnA"+

"SiZKAREViSfFViUfGViVfHVhRfEfnffO2jUBJ2jUBnASiaLAREARCXYfViZfKXgafViZfKfARCXhVfV"+

"iZfKChdXgafViZfKViXfJnnfARCXhVfViZfKXhWfViZfKfARCXYfViZfKXhWfViZfKffnffAhhHVgef"+

"PJ2jVBnASiaLAREARCXYfViZfKChAXgafViZfKViXfJnnfARCXhVfViZfKXgafViZfKfARCXhVfViZf"+

"KXhWfViZfKfARCXYfViZfKXhWfViZfKffnffJ2jaBnAEjiNfRCViZfKViafLffJ2jcBnABXhNfXhOfj"+

"KfViPfAnfABnSnbyBn0ABf2jeBnAjSfAShJ4E0AhAhK4F0AhAiY4C0AhAiR4D0AiAiS4F0AiAiQ4C0A"+

"iAiU4G0AiAiV4H0AiAiW4I0AiAiZ4K0AiAia4L0AiAiX4J0AiAiG4B0AiAiP40BiAN40BhAiO4B0AhA"+

"ge4D0AhAhR4E0AiAGMAhMA2jfBM2kCBbyBn0ABg2kEBbyBn0AIJ2kGBnASiRAEjzPiBjDjUjJjPjOiS"+

"jFjGjFjSjFjOjDjFicfntnftJ2kHBnAEXzLjQjVjUiQjSjPjQjFjSjUjZidfViRfARCEjCfRBFeHjDj"+

"IjBjOjOjFjMffEjCfRBFeJjTjFjMjFjDjUjJjPjOffffJ2kJBnASiEBEjiFfntnftJ2kKBnAEXzMjQj"+

"VjUiSjFjGjFjSjFjOjDjFiefViEfBRCEjCfRBFeGjUjBjSjHjFjUffViRfAffJ2kMBnASiRAEjicfnt"+

"nftJ2kNBnAEXiMfViRfARDEjCfRBFeHjDjIjBjOjOjFjMffEjCfRBFeHjDjIjBjOjOjFjMffEjCfRBF"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j"+

"DjUjFjYjUjDfFeEiXjBjJjUffnfJLnABXzFjXjJjEjUjIjOfXzNjQjSjFjGjFjSjSjFjEiTjJjajFjP"+

"fXjMfVjBfyBndlAfJMnABXzHjKjVjTjUjJjGjZjQfXjMfVjBfyBneGjDjFjOjUjFjSfJOnAEXzEjTjI"+

"jPjXjRfVjBfyBnfJQnASTyBnctftOSJSnAEXzOjTjVjTjQjFjOjEiIjJjTjUjPjSjZjSfXJfjKfRCFe"+

"KiTjUjSjBjJjHjIjUjFjOFeGjNjBjJjOhIhJffAXzGjMjFjOjHjUjIjTfXzJjEjPjDjVjNjFjOjUjTj"+

"UfjKfnOUbWn0ACJWnAEjBfRDEjCfRBFeJjVjOjEjPiFjWjFjOjUffjDfXEfjFfffJXnAEXjSfXJfjKf"+

"RCFeEiVjOjEjPFeAffAhhHVTfyBnJganAEXzFjDjMjPjTjFjVfVjBfyBnfJgcnABXhNfXhOfjKfViPf"+

"yBnfADT4C0AiAiP40BiAjB4B0AiAADAgcByB");

Jarda Bereza
Inspiring
September 15, 2018

r-bin interesting... it works for trapezoid but it failed with different shape.

What is the source of this script? Is it yours? Is there reason for obfuscation?

I have undeform script but for now, it works only with smart objects and affine transformations. Not trapezoids, perspective, etc.

I hope Tom Ruark could advise when he returns from vacation.

Jarda Bereza
Inspiring
November 10, 2018

Jarda Bereza

 

r-bin  interesting... it works for trapezoid but it failed with different shape.

What is the source of this script? Is it yours? Is there reason for obfuscation?

 

I have undeform script but for now, it works only with smart objects and affine transformations. Not trapezoids, perspective, etc.

I hope Tom Ruark could advise when he returns from vacation.

In continuation of the conversation. )

I'm here interested in parsing a PSD file.
While things are moving slowly. But I discovered an amazing thing.
This script returns the smart object to its original 100% state from any distortion.
The script is extremely simple. Does not specifically use file parsing. It is assumed that there is only one smart object in the file, the transformation can be any, but does not contain warp, the file is saved at least once on the disk.

If you are interested in this method, you can develop it.

 

var file = activeDocument.fullName;

 

activeDocument.save();

 

file.open("e");

file.encoding = "BINARY";

 

var len = file.length;

 

if (len > 100000) len = 100000;

 

var buff = file.read(len);

 

var n = buff.indexOf("8BIMSoLd");

 

if (n > 0)

    {

    var off = n+20;

 

    var d = new ActionDescriptor();

    d.fromStream(buff.substr(off))

 

    var w = d.getObjectValue(stringIDToTypeID("size")).getDouble(stringIDToTypeID("width"));

    var h = d.getObjectValue(stringIDToTypeID("size")).getDouble(stringIDToTypeID("height"));

 

    var list = new ActionList()

 

    list.putDouble(0);

    list.putDouble(0);

 

    list.putDouble(w);

    list.putDouble(0);

 

    list.putDouble(w);

    list.putDouble(h);

 

    list.putDouble(0);

    list.putDouble(h);

 

    d.putList(stringIDToTypeID("transform"), list);

    d.putList(stringIDToTypeID("nonAffineTransform"), list);

 

    file.seek(off, 0);

    file.write(d.toStream());

    file.close();

 

    app.activeDocument.suspendHistory("TMP", "");

    executeAction(stringIDToTypeID("revert"), undefined, DialogModes.NO);

    runMenuItem(stringIDToTypeID("freeTransform"));

    }

else

    {

    alert("No Smart Object found")

    file.close();

    }

 

upd.

works in CS6


r-bin That is smart. So you basically find actionDescriptor in binary form for smart object transformation and then you create regular descriptor from it, find four corners of smart object and you set them to its width and height also present in that descriptor then you convert it back to binary and rewrite original data. So after PSD reopen it should be ok.