1 2 Previous Next 46 Replies Latest reply on Feb 11, 2018 5:07 AM by JJMack

# Algorithm for fitting different sized rectangles in a larger rectangle

I need script an algorithm to calculate best fit for rectangles in a larger rectangle.. and the larger rectangle changes size dynamically.

The dimensions of each rectangle include several 5 * 5 rectangles.

like the picture below.

pleas help me.

• ###### 1. Re: Algorithm for fitting different sized rectangles in a larger rectangle

First off you may want to post over at

Photoshop Scripting

I need script an algorithm to calculate best fit for rectangles in a larger rectangle.. and the larger rectangle changes size dynamically.

What exactly do you mean, especially by »changes size dynamically«?

And what about the white borders?

The dimensions of each rectangle include several 5 * 5 rectangles.

Some of the images appear to be square, so what are the images’ proportions?

• ###### 2. Re: Algorithm for fitting different sized rectangles in a larger rectangle

i want place images or textFrame in page.Like attached photo.

The dimensions of the document page may be dynamic.example : For the newspaper 50 * 70

For the magazine 30 * 20.

i want script i want place images or textFrame in page.

white borders is margin.

Some of the images appear to be square, so what are the images’ proportions?: example :The dimensions of a 10 × 2 image include 2 number 5 × 2 frame in horizontal direction.That is, each image is measured with a 5 * 2 fram. Please attention to the photo below.

ok?

.

• ###### 3. Re: Algorithm for fitting different sized rectangles in a larger rectangle

i want place images or textFrame in page.Like attached photo In the previous post.

The dimensions of the document page may be dynamic.example : For the newspaper 50 * 70

For the magazine 30 * 20.

i want script i want place images or textFrame in page.

white borders is margin.

Some of the images appear to be square, so what are the images’ proportions?: example :The dimensions of a 10 × 2 image include 2 number 5 × 2 frame in horizontal direction.That is, each image is measured with a 5 * 2 fram. Please attention to the photo below.

ok?

.

• ###### 4. Re: Algorithm for fitting different sized rectangles in a larger rectangle

I fail to understand the principles governing the image-placement and -clipping so far.

How many images need to be placed, can certain images be dropped, do they have content that must not be clipped, …?

And as mentioned before you should post on the Scripting Forum.

But this seems like a bad fit of a task for Photoshop – Indesign (or possibly Illustrator) might provide preferable output (especially if texts are involved) and more convenience in image-placement.

• ###### 5. Re: Algorithm for fitting different sized rectangles in a larger rectangle

giude me.

And as mentioned before you should post on the Scripting Forum.?

My description was obvious.

• ###### 6. Re: Algorithm for fitting different sized rectangles in a larger rectangle
My description was obvious.

You think so?

You did not make clear how many fields are indispensably necessary, how many images have to be placed, how the image can be clipped, …

And as mentioned before you should post on the Scripting Forum.?

In post 1 I provided a Link to the Photoshop Scripting Forum:

First off you may want to post over at

Photoshop Scripting

• ###### 7. Re: Algorithm for fitting different sized rectangles in a larger rectangle

The image should not be clipped.

jast place in page.

• ###### 8. Re: Algorithm for fitting different sized rectangles in a larger rectangle

Hi

I've moved your post to the Photoshop Scripting forum

Dave

• ###### 9. Re: Algorithm for fitting different sized rectangles in a larger rectangle

Please give a meaningful description of the intended process.

The numbers in your screenshot from above (2x5, 4x5, 2x10) seem to disregard the gutters so if your images actually had those proportions (2x5, 4x5, 2x10) they would clash with the grid or have to be clipped.

• ###### 10. Re: Algorithm for fitting different sized rectangles in a larger rectangle

Please provide an algorithm for arrenging photos of different dimensions.

• ###### 11. Re: Algorithm for fitting different sized rectangles in a larger rectangle

How do I do this?

I do not know.

• ###### 12. Re: Algorithm for fitting different sized rectangles in a larger rectangle

I do no thinhk think you have a claer idea of what you want to do.Even undestand that if you want to fit an image to an area without distortion if the image has a different aspect ratio than the area the resize image will not fill the area. You are not going to be able to place image with random aspect ratio neatly like you show here:

Even in the example you show here it looks like the images have been resize to fill the areas  and the excess masked of to constrain the image to the areas. So the image compositions have been changed to a virtual centered crop the aspect ration of the different image areas aspect ratio.

• ###### 13. Re: Algorithm for fitting different sized rectangles in a larger rectangle

no . No . it is not like this.

• ###### 14. Re: Algorithm for fitting different sized rectangles in a larger rectangle
no . No . it is not like this.

I for one still do not fully understand your proposed rules governing the placement of images.

So instead of claiming you made your point maybe you should try to make it more clearly.

What are the  actual dimensions of the images that are to be placed?

• ###### 15. Re: Algorithm for fitting different sized rectangles in a larger rectangle

It is easy to make template for  media that have different size pages.  However you are not going to be able to layout images with different random aspect ration neatly in some matrix of images in an orderly fashion.   If you fit images to an area there will be aspect ratio mismatches leaving white space on at least one image side you will not have the same border around all images.  If you fill an area and mask excess off the images compositions will be cropped and if the aspect ratio change is great the resulting composition will most likely not be acceptable.    You have been asked to be more specific about what you actually want to do and for image can have any aspect ratio image can be resize uo or down in size  they will still have their original aspect ration and very like not match the area you want to position it to aspect ratio.   Here you show I tiled layout where  one 4x5 fills 2 2x5 areas plus the gap between the 2 2x5 areas How do you purpose to do change the 4x5 height to larger then 4 and not distort the image. Also show a 2x10  being stretched wider than 10.  You do not have a good understanding of what you want to do.  Do not care about what you don't have care about what you do have and what you want to do with what you have. Right not what you show would distort your images streatching them that way.

• ###### 16. Re: Algorithm for fitting different sized rectangles in a larger rectangle

Their original dimensions.

• ###### 17. Re: Algorithm for fitting different sized rectangles in a larger rectangle

No . I do not know why you do not understand.

It's easy.

• ###### 20. Re: Algorithm for fitting different sized rectangles in a larger rectangle

shahriara7551080  wrote

OK I will agree that the frame pointed to with the red arrow is const  whatever  you define const to be it is what it is..  I do not agree that the other frame are like your const frame other than they are rectangular. They are different in size and aspect ratio. Only images with matching aspect ratio can be perfectly fitted into a frame.   The frame opening aspect ratio and the images aspect ratio must be a perfect match.  The example red arrow is point to an inner 2*5 frame that is different in size than your const red arrow frame.  the margins between frames differ.  The only  common thing I see is all frame are rectangular and some frames have side the same length as some other frames. The height of all may be a multiple of 2 but the width of all are not a multiple of 5 because the margins between frames in the layout are not a multiple 5.  The bottom frame is noted as 2*12  it spanning 4 upper frames. if the upper frame are 5 wide the  bottom frame is over 20 wide you do not understand what you want to do so it impossible for you to tell up what you want to do. Even you example is incorrect it is inconsistent.

• ###### 21. Re: Algorithm for fitting different sized rectangles in a larger rectangle

Sorry

The bottom frame is  2*60

• ###### 22. Re: Algorithm for fitting different sized rectangles in a larger rectangle

You assume that all margins are equal.

And all rectangles are composed of a rectangle of 2 *5

ok?

• ###### 23. Re: Algorithm for fitting different sized rectangles in a larger rectangle

shahriara7551080  wrote

You assume that all margins are equal.

And all rectangles are composed of a rectangle of 2 *5

ok?

If all framed images are (some multiple of 2) x (some multiple of 5) in size as you show. All image would not have a 2:5 aspect ratio and most likely image in you would get would not have matching aspect ratios and even if they were most likely you could not layout a random numbers out in a somewhat symmetric layout that forms a rectangle. Like your example form a rectangle.  You could not Handle most standard image sizes with aspect ratios of 2:3, 5x7 etc.  About the only standard size you will be will have a 4:5 aspect  ratio, 4x5, 8x10, 16x20 etc. You need to specify exactly what you want to do and what you want to do must also be possible.

• ###### 24. Re: Algorithm for fitting different sized rectangles in a larger rectangle

My problem is like tiling.But easier.

Can you give me a tiling script?

• ###### 25. Re: Algorithm for fitting different sized rectangles in a larger rectangle

shahriara7551080  wrote

My problem is like tiling.But easier.

Can you give me a tiling script?

Tiling is easy you are right. Tile are uniform in  size or there a pattern of different size tiles you follow to fill the rectangular wall space. area the matches a possible tile layout size that matches  the wall aspect ratio and size. Otherwise you need to use a tile cutter. I have made a tiling script available . Its not what you want.

What you are trying to do is more like making a puzzle the solution fit a wall rectangle. Will they even fit well.  How do you do that? When tile size and aspect ratio vary and you have no designed tile pattern.  What do you do  if you have too many or too few image for the rectangle wall space. Do you use a tile cutter or use a lot of filler grout.

Fitting image to a know tile layout is also easy if you will be satisfied with image that have been resize and may have some lost content.

It hard to deal with the unknown. You need a design plan to handle the number of image you are going to use.   Know how many image  know the different image sizes and the number of each different size image so you can calculate there total surface  area and then try to come with a tiling pattern that will result in a rectangle being file the will fit within  the rectangle wall space then adjust spacing to fill the wall space size.  What you want to do is far from easy.

• ###### 26. Re: Algorithm for fitting different sized rectangles in a larger rectangle

Do you even know coding?

• ###### 27. Re: Algorithm for fitting different sized rectangles in a larger rectangle

I hack at Photoshop scripting it is easy to see you do not know Photoshop well and know nothing about programming so can not script Photoshop.   Here is a link that describes a script  I made avaible as part of my Photoshop Photo Collage Toolkit.  It tiles images.

• ###### 28. Re: Algorithm for fitting different sized rectangles in a larger rectangle

i want this script indesign .

• ###### 29. Re: Algorithm for fitting different sized rectangles in a larger rectangle

Re-explain the issue?

# Algorithm script for fitting different sized rectangles in a larger rectangle

• ###### 31. Re: Algorithm for fitting different sized rectangles in a larger rectangle

pleas help me.

• ###### 32. Re: Algorithm for fitting different sized rectangles in a larger rectangle

shahriara7551080  wrote

i want this script indesign .

Why are you posting you request in Photoshop scripting forum then?

• ###### 33. Re: Algorithm for fitting different sized rectangles in a larger rectangle

shahriara7551080  wrote

# Algorithm script for fitting different sized rectangles in a larger rectangle

Can only be done perfectly if the image and the larger rectangle has the same aspect ratio as the image. You can not fit a square peg into a rectanular farme that does not have a square aspect ratio perfectly  there will be borders or distortion or content loss.

• ###### 34. Re: Algorithm for fitting different sized rectangles in a larger rectangle

We are trying to help you.  You do not understand what we write.  There is a communicating problem. You need to try to understand what user have written to you.

• ###### 35. Re: Algorithm for fitting different sized rectangles in a larger rectangle

I do not want to fit the square into the rectangle.

i want place text frames in page indesign.(like tailing)

This is done before.But I do not know its algorithm.

• ###### 36. Re: Algorithm for fitting different sized rectangles in a larger rectangle

i want place text frames in page indesign.

There may be an GAP between the text frames.

The next step is filled with default text frames.

Give me a script that puts images in different sizes(The dimensions of the images are proportional to the page.That is, do not cut the images) on the page.

tanks.

• ###### 37. Re: Algorithm for fitting different sized rectangles in a larger rectangle

Why are you using the Photoshop Scripting forum then?  I have no idea what a text frame is even In Photoshop we have text  boxes that text will flow in like align like paragraph How nuch text will fit is a function of font size and box shape and size not always a rectangle or squared with the canvas.  Where would text frames come from? You should try using the indesign scripting forum InDesign Scripting

• ###### 38. Re: Algorithm for fitting different sized rectangles in a larger rectangle

My output looks like a picture. Exactly .

Can you give me this script for me?

• ###### 39. Re: Algorithm for fitting different sized rectangles in a larger rectangle
1 2 Previous Next