write a function to figure out the required size of your canvas image (python) - we need to know the size (width and hei

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

write a function to figure out the required size of your canvas image (python) - we need to know the size (width and hei

Post by answerhappygod »

write a function to figure out the required size of your canvas
image (python)
- we need to know the size (width and height) of the canvas
image so that your thumbnails will fit on it when pasted into the
canvas.
- As this (once again) should work for any kind of number of
images in any other folder, this cannot be hardcoded for your pics1
folder buy needs to be solved universally with a function.
- the function will get:
- a number of thumbnails
- the bounding box of the thumbnails
- the desired number of thumbnails __per row__
- from the number of thumbnails and the thumbnails per row given
this you need to figure out how many rows of thumbnails you
need.
- in the example given at the start I had 3 images and wanted 3
per row. The folder pics1 contains 3 images, so I have only one
row
Examples:
- if I instead have 6 thumbnails and I still want 3 per row, I
need 2 rows
- for 4 or 5 thumbnails with 3 per row, I need also need 2 rows
(__It's OK to have empty spots on your canvas!__)
- for 6 thumbnails with 2 per row, I need 3 rows
- for 6 thumbnails with 4 per row, I need 2 rows
- hint: `math.ceil(fl)`, when given a floating point number,
will return the __next higher integer number:__
- `math.ceil(1.2)` => 2
- `math.ceil(1.0)` => 1
- `math.ceil(2.0)` => 2
- Once you have the number of rows, figure out the size of the
canvas:
- in the example, the bounding box for making my thumbnails was
200 x 200 pixels
- for 3 thumbnails in 1 row, the canvas needs to be 600 x
200
- for 6 thumbnails with 4 per row I get 2 rows and the canvas
would need to be 800 x 400 pixels
- put the canvas size in a list with width and height, e.g.
`[600, 200]` or `[800, 400]`
- return a list with the canvas size (as a list) and the number
of rows: e.g. `[[600, 200], 1]` or `[[800, 400], 2]`
Answer:
def calc_canvas_size(num_thumbnails, bounding_box=[50,50],
num_thumbnails_per_row=3):
????????
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply