Skip to main content
Inspiring
October 4, 2023
Answered

Set width size of exportPNG24 with scripting

  • October 4, 2023
  • 3 replies
  • 359 views

I'm exporting a png 24 image but I'd like to set hte width size.  In the documentation it only specifies scale but not an actual size in example 1400.

 

      fileTypeSmart = ExportType.PNG24;
      exportOptionsSmart = new ExportOptionsPNG24();
      exportOptionsSmart.transparency = isTrue(settings.png_transparent);
app.activeDocument.exportFile(new File(imgPath.replace('.jpg', '-smartObj.png')), fileTypeSmart, exportOptionsSmart);

 

Is there away for me to add a width?

I attempting this: 

exportOptionsSmart.width = 1800;
But it does not function.
This topic has been closed for replies.
Correct answer OhmsG

Since it appears that it's not an option I ended up doing it by calculating the artboard width and then calculating the scale percentage for the desired image size.

var scaleToSmart = Math.round( (templateSize / app.activeDocument.width) * 100 )

3 replies

OhmsGAuthorCorrect answer
Inspiring
October 4, 2023

Since it appears that it's not an option I ended up doing it by calculating the artboard width and then calculating the scale percentage for the desired image size.

var scaleToSmart = Math.round( (templateSize / app.activeDocument.width) * 100 )
Jacob Bugge
Community Expert
Community Expert
October 5, 2023

Thank you for sharing your nice solution, OhmsG.

 

That is exactly the same way we can get Illy (job description Adobe Illustrator) to calculate the percentage for us in a normal scaling; and she does it accurately.

 

 

 

Without my having any scripting knowledge, with the Math.round it seems to round to an integer value of the percentage?

 

If that is the case, I believe it must be better to use whichever non integer value gives the accurate width.

 

 

Ton Frederiks
Community Expert
Community Expert
October 4, 2023

Export for screens and Asset Export panel lets you specify a width and save a preset.

But that is not a script

Jacob Bugge
Community Expert
Community Expert
October 4, 2023

OhmsG,

 

Maybe far too far out, but how about something based upon the legacy Save for Web, which works in Image Size?