Skip to main content
Participant
July 3, 2025
Question

Illustrator Script Problem – Design gets stretched when resizing

  • July 3, 2025
  • 1 reply
  • 372 views

 

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!

1 reply

Sergey Osokin
Inspiring
July 4, 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);

 

Participant
July 4, 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

Sergey Osokin
Inspiring
July 4, 2025

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.