Skip to main content
garrykillian
Participant
September 22, 2016
Answered

Override HorizontalScale limits (776.19) when exporting JPG

  • September 22, 2016
  • 1 reply
  • 1116 views

I'm trying to export jpeg files from multiple eps files (with many different artboard sizes) with a specific size - 5000px on long edge. But when artboard is too small horizontalScale exceed its range and script fails. Is there anyway I can solve this problem?

Here is my script:

var doc = app.activeDocument;

var abActive  = doc.artboards[doc.artboards.getActiveArtboardIndex()];

var artWidth = abActive.artboardRect[2] - abActive.artboardRect[0];

var artHeight = abActive.artboardRect[1] - abActive.artboardRect[3];

if (artWidth>=artHeight)

{

   var fileName = doc.fullName.toString();

    var exportOptions = new ExportOptionsJPEG();

  

    var fileSpec = new File(fileName);

    exportOptions.antiAliasing = true;

    exportOptions.artBoardClipping = true;

    exportOptions.qualitySetting = 100;

    exportOptions.horizontalScale = (5000/artWidth)*100;

    exportOptions.verticalScale = (5000/artWidth)*100;

  

    doc.exportFile( fileSpec, ExportType.JPEG, exportOptions );

   }

else

{

    var fileName = doc.fullName.toString();

    var exportOptions = new ExportOptionsJPEG();

  

    var fileSpec = new File(fileName);

    exportOptions.antiAliasing = true;

    exportOptions.artBoardClipping = true;

    exportOptions.qualitySetting = 100;

    exportOptions.verticalScale = (5000/artHeight)*100;

    exportOptions.horizontalScale = (5000/artHeight)*100;

  

  

    doc.exportFile( fileSpec, ExportType.JPEG, exportOptions );

}

P.S. I thought about cheking artboard size before export and if it too small - scale it to needed size, but it would make export process really slow.

This topic has been closed for replies.
Correct answer garrykillian

The final recipe will show? I was very interested in it (including the handling of third-party software).

Thank you!


var doc = app.activeDocument;

var abActive  = doc.artboards[doc.artboards.getActiveArtboardIndex()];

var artWidth = abActive.artboardRect[2] - abActive.artboardRect[0];

var artHeight = abActive.artboardRect[1] - abActive.artboardRect[3];

         if (artWidth>=artHeight)

         {

           var fileName = doc.fullName.toString();

            var exportOptions = new ExportOptionsPNG24();

           

            var fileSpec = new File(fileName);

            exportOptions.antiAliasing = true;

            exportOptions.artBoardClipping = true;

            exportOptions.transparency = false;

            exportOptions.qualitySetting = 100;

            exportOptions.horizontalScale = (5000/artWidth)*100;

            exportOptions.verticalScale = (5000/artWidth)*100;

           

            doc.exportFile( fileSpec, ExportType.PNG24, exportOptions );

           }

        else

        {

            var fileName = doc.fullName.toString();

            var exportOptions = new ExportOptionsPNG24();

           

            var fileSpec = new File(fileName);

            exportOptions.antiAliasing = true;

            exportOptions.artBoardClipping = true;

            exportOptions.transparency = false;

            exportOptions.qualitySetting = 100;

            exportOptions.verticalScale = (5000/artHeight)*100;

            exportOptions.horizontalScale = (5000/artHeight)*100;

           

            doc.exportFile( fileSpec, ExportType.PNG24, exportOptions );

        }

doc.close(SaveOptions.DONOTSAVECHANGES);

I also add command to close file witout saving. When creating action with this script and than batch for multiple files it helps to lower script work time.

For PNG to JPG convert I use XnConvert it's free and have all needed functionality to batch convert files.

1 reply

o-marat
Inspiring
September 23, 2016

Hi, garrykillian!

How do you scale?

New  You can try export the artboards to PDF-files, open this files in Photoshop and then make jpg-files through Photoshop.

garrykillian
Participant
September 23, 2016

Hi, o-marat

In JPG exportoptions there are properties: horizontalScale and verticalScale (by the default - 100% and have range: 0.0 to 776.19%)

So I calculate need scale amount by 5000/ImageLongSide dimension * 100

It works great for artboard dimensions more that 600-700 (px,pt etc.) but when it lower like 100 pt - by this formula scale factor exceed described above range, and script crashes.

p.s. there are nearly 6000 files to export

You can try export the artboards to PDF-files, open this files in Photoshop and then make jpg-files through Photoshop.

If exporting to diffenet format I think PNG24 will work better.

garrykillian
garrykillianAuthorCorrect answer
Participant
September 25, 2016

The final recipe will show? I was very interested in it (including the handling of third-party software).

Thank you!


var doc = app.activeDocument;

var abActive  = doc.artboards[doc.artboards.getActiveArtboardIndex()];

var artWidth = abActive.artboardRect[2] - abActive.artboardRect[0];

var artHeight = abActive.artboardRect[1] - abActive.artboardRect[3];

         if (artWidth>=artHeight)

         {

           var fileName = doc.fullName.toString();

            var exportOptions = new ExportOptionsPNG24();

           

            var fileSpec = new File(fileName);

            exportOptions.antiAliasing = true;

            exportOptions.artBoardClipping = true;

            exportOptions.transparency = false;

            exportOptions.qualitySetting = 100;

            exportOptions.horizontalScale = (5000/artWidth)*100;

            exportOptions.verticalScale = (5000/artWidth)*100;

           

            doc.exportFile( fileSpec, ExportType.PNG24, exportOptions );

           }

        else

        {

            var fileName = doc.fullName.toString();

            var exportOptions = new ExportOptionsPNG24();

           

            var fileSpec = new File(fileName);

            exportOptions.antiAliasing = true;

            exportOptions.artBoardClipping = true;

            exportOptions.transparency = false;

            exportOptions.qualitySetting = 100;

            exportOptions.verticalScale = (5000/artHeight)*100;

            exportOptions.horizontalScale = (5000/artHeight)*100;

           

            doc.exportFile( fileSpec, ExportType.PNG24, exportOptions );

        }

doc.close(SaveOptions.DONOTSAVECHANGES);

I also add command to close file witout saving. When creating action with this script and than batch for multiple files it helps to lower script work time.

For PNG to JPG convert I use XnConvert it's free and have all needed functionality to batch convert files.