Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Override HorizontalScale limits (776.19) when exporting JPG

Community Beginner ,
Sep 22, 2016 Sep 22, 2016

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.

TOPICS
Scripting
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Sep 25, 2016 Sep 25, 2016

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;

           

...
Translate
Adobe
Engaged ,
Sep 23, 2016 Sep 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 23, 2016 Sep 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 23, 2016 Sep 23, 2016

I would make the following algorithm:

  • Save artbords to PDF (to then open in Photoshop).
  • Calculate to each artbords the resolution at which you need to open the PDF-file in Photoshop (that to get on the larger side the 5000 px).
  • Convert PDF to JPG through Photoshop.

Thus, the task is parallelized: Illustrator saves the PDF-files, Photoshop convert PDF to JPG.

The output is JPG-files with a resolution of 72 dpi and a size of 5000px on the larger side.

For example, a function that calculates the resolution, with which to open the PDF-file in Photoshop:

function getOpenPhotoshopResolution () {

  var d         = activeDocument,

      artbAct   = d.artboards[d.artboards.getActiveArtboardIndex ()],

      artbW     = artbAct.artboardRect[2] - artbAct.artboardRect[0],

      artbH     = artbAct.artboardRect[1] - artbAct.artboardRect[3],

      LONG_SIDE = 5000,

      BASE_RES  = 72,

      openShopRes;

  if (artbW >= artbH) {

    openShopRes = LONG_SIDE * BASE_RES / artbW;

  } else {

    openShopRes = LONG_SIDE * BASE_RES / artbH;

  }

  return openShopRes;

}

New Your code can be packaged in a try-catch construct and when an error occurs, then an alternative way to go - through Photoshop.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 23, 2016 Sep 23, 2016

But 6000 files ...

In this case, you may need a batch export of all files to pdf (through Illustrator action or script, artboards are automatically converted into pages of pdf-files, as I think).

Then the files are processed using some third-party program ...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 24, 2016 Sep 24, 2016

Yeah! Thanks!

Your idea to export in PDF inspired me to try export from Illustrator in other image formats and PNG worked good.

Instead of JPG, PNG does not have this limit in scale.

And after export it easy to convert all PNG into JPG using something like ACDSee etc.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 24, 2016 Sep 24, 2016

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

Thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 25, 2016 Sep 25, 2016
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines