Copy link to clipboard
Copied
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.
...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;
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I would make the following algorithm:
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.
Copy link to clipboard
Copied
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 ...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
The final recipe will show? I was very interested in it (including the handling of third-party software).
Thank you!
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now