Skip to main content
Inspiring
January 4, 2020
Answered

Scripting: resize image based on resolution

  • January 4, 2020
  • 2 replies
  • 4627 views

I have a variable I capture that has a resolution value which is a pixels/cm value.  I then want to resize an image using that resolution variable and make sure the unit measurement is set to pixel/cm and make sure resampling is off so that it resizes 1:1.

 

I thought that:

imageResize(undefined,undefined,res.variable,ResampleMethod.None)

would be the right fit, but it is not. I tried using the scriptListener to grab those actions by doing it manually, but no luck. Can someone help?

 

 

This topic has been closed for replies.
Correct answer greenrookie

I think you need to convert cm to pixels/inch

 

NewResolution  = res.variable x 2.54

imageResize(undefined,undefined,NewResolution,ResampleMethod.NONE)

2 replies

Inspiring
January 4, 2020

You need to convert cm to pixels in the variable res.variable

greenrookieCorrect answer
Inspiring
January 4, 2020

I think you need to convert cm to pixels/inch

 

NewResolution  = res.variable x 2.54

imageResize(undefined,undefined,NewResolution,ResampleMethod.NONE)

JJMack
Community Expert
Community Expert
January 4, 2020

They want an images with a 1:1  Aspect Ratio. If they resize unconstrained to a 1:1 Aspect Ratio no matter what resolution the document has the image will distort. If they Crop the image to a 1:1 aspect ratio they will lose some image content the images resolution will not change.  They could also add canvas so the image has a boarder to make the image have a 1:1 aspect ratio. They need to decide how the want to change the image to have a 1:1 aspect ratio. Add a Boarder, Crop, or Distort. Content Aware Scale also distorts the image but tries to preserve recognized objects aspect ratio their image looks like a unique finger print it will distort if resized to a 1:1 aspect ratio. 

 

They do not want to Resample they must Crop or Add Canvas.

JJMack
JJMack
Community Expert
Community Expert
January 4, 2020

That would be a Crop not a resize. You need to discard part of you image to change its aspect ratio to 1:1 if its not square. You need to have some process to do that. ie. Make a centered crop or crop orientation from some corner.  Or have  an interactive action where you can position the 1:1 aspect crop selection for the action. It not hard to do.

 

JJMack