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

Illustrator Script Problem – Design gets stretched when resizing

New Here ,
Jul 03, 2025 Jul 03, 2025

 

Hi,
I created this custom JSX script in Illustrator to export selected designs. Everything works fine, except for one issue: the design gets stretched instead of scaling properly and fills the artboard, rather than maintaining the design's original ratio and proportions.

Here’s the part of the code that resizes the design:

group.position = [docWidth/2 - (width/2), docHeight/2 + (height/2)];

group.resize((docWidth - 10) / width * 100, (docHeight - 10) / height * 100);

Problem:
This code changes the aspect ratio and stretches the design.

I want the design to keep its original aspect ratio and be scaled proportionally, with about a 5px margin

Can someone help me fix this part so the design doesn’t stretch?

Thanks!

TOPICS
Bug , Experiment , Scripting , SDK , Tools
474
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
Adobe
Enthusiast ,
Jul 03, 2025 Jul 03, 2025

In order for the proportions of the object to be preserved, you must pass in resize() the same percentage of transformation for X, Y. For you, the values are calculated from docWidth and docHeight, which means they can be different percentages. Try this

var minDocSize = Math.min(docWidth, docHeight);
group.resize((minDocSize - 10) / width * 100, (minDocSize - 10) / height * 100);

 

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
New Here ,
Jul 04, 2025 Jul 04, 2025

thanks Sergey. I tried this logic, it still stretches the design Also, this time around it chooses the wrong resolution 
Originally, i had a condition that if the design ratio is more has  more height than width, then it should choose 4500x5400 resolution (portrait) this it did the opposite and chose horizontal, do you want me to share my original script so you can have a closer look? i'm not much familiar with logic building for scripts

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
Enthusiast ,
Jul 04, 2025 Jul 04, 2025
LATEST

You can also show screenshots: Before > After, what you originally drew and what you want to get. That is, manually scale and show what you expect from the script. The new information about vertical and horizontal resolutions still raises more questions about the original description of the problem.

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