Skip to main content
tokuredit
Inspiring
October 23, 2018
Answered

Help with the size of the photo on the canvas

  • October 23, 2018
  • 1 reply
  • 849 views

Hello!

How to resize the photo inside the painting canvas based on the size of the height preserving its proportion with scripts?

Thank you!

This topic has been closed for replies.
Correct answer tokuredit

Sorted out!

Source:

https://forums.adobe.com/message/9912938#9912938

1 reply

tokuredit
tokureditAuthorCorrect answer
Inspiring
October 23, 2018
Kukurykus
Legend
October 23, 2018

Post your code then

tokuredit
tokureditAuthor
Inspiring
October 23, 2018

Kukurykus​ I used only these lines of the script JJMack

var SWidth  = app.activeDocument.width.as('px');   

var SHeight = app.activeDocument.height.as('px');   

var bounds = app.activeDocument.activeLayer.bounds;   

var LWidth = bounds[2].as('px')-bounds[0].as('px');   

var LHeight = bounds[3].as('px')-bounds[1].as('px');  

 

 

var userResampleMethod = app.preferences.interpolation;  // Save interpolation settings   

app.preferences.interpolation = ResampleMethod.BICUBIC; // resample interpolation bicubic   

if (LWidth/LHeight<SWidth/SHeight) { // Smart Object layer Aspect Ratio less the Canvas area Aspect Ratio    

   var percentageChange = ((SWidth/LWidth)*100);  // Resize to canvas area width   

   activeDocument.activeLayer.resize(percentageChange,percentageChange,AnchorPosition.MIDDLECENTER);   

   }   

else {    

  var percentageChange = ((SHeight/LHeight)*100); // resize to canvas area height   

  activeDocument.activeLayer.resize(percentageChange,percentageChange,AnchorPosition.MIDDLECENTER);   

   }   

app.preferences.interpolation = userResampleMethod; // Reset interpolation setting   

 

 

app.activeDocument.selection.selectAll(); 

align('AdCH'); align('AdCV'); 

app.activeDocument.selection.deselect(); 

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){} 

}