x404.co.uk http://www.x404.co.uk/forum/ |
|
Resizing an image and keeping aspect ratio http://www.x404.co.uk/forum/viewtopic.php?f=4&t=17705 |
Page 1 of 1 |
Author: | Fogmeister [ Wed Nov 21, 2012 10:23 am ] |
Post subject: | Resizing an image and keeping aspect ratio |
Is it just me who has done this before? The new back-end dev has written an image download API that allows me to provide X and Y sizes to resize the image. It was just squashing the image into the given size and screwing with the aspect ratio. I asked him if he could keep the aspect ratio and make the image "fit" into the size I give. He seriously had no idea what I meant. I drew out a picture telling him I would always provide a perfect square (i.e. same x and y) and the image would be resized to fit in the square. He then asked what colour I want the surrounding space in the square to be. I then showed him the iPhone how it resizes based on the orientation but keeps the aspect ratio. Still didn't get it. In the end I wrote out how to do it in pseudo code for him. I made a mistake though (not on purpose) which meant I was multiplying the given size by the scale instead of the image size. He told me it was done and I checked and it wasn't. I then had to debug my pseudo code to work out what was wrong and let him know so he could change his code. Surely that is something that could have been checked by him?! [/rant] Anyway, would you know what I meant if I asked you to resize an image to fit a given size and keep the aspect ratio? Would you know how to do it? |
Author: | JJW009 [ Wed Nov 21, 2012 11:17 am ] |
Post subject: | Re: Resizing an image and keeping aspect ratio |
I would ask "what colour I want the surrounding space in the square to be" ... If you fit the entire picture into a square, then there will be blank space unless the picture is also square. On a phone, I'd probably make that black. The alternative is to crop the image so the smaller axis fits exactly. However, you say nothing of cropping. This is how the wallpaper on my pad works. The final alternative is to pick something in between, cropping slightly but still having black bars. This is much like showing wide-screen films on a 4:3 screen. |
Author: | Fogmeister [ Wed Nov 21, 2012 11:48 am ] | |||||||||
Post subject: | Re: Resizing an image and keeping aspect ratio | |||||||||
But the square is just an abstract size. I didn't want the total image to be that size. It's just a constraint on the size of the image. If that makes sense? Ah, I'm not actually displaying the image from the API. I'm just storing it to the iPhone. I just don't want to download a 12MP image. So I provide a size constraint and download the resized version. That's what the API is for. |
Author: | EddArmitage [ Wed Nov 21, 2012 12:31 pm ] |
Post subject: | Re: Resizing an image and keeping aspect ratio |
So you're wanting the image to be resized so that it's the biggest image that could fit into the given rectangular space? E.g. If I have a square image, and a very wide and short space, the square will be resized so that it's side length is that of the shortest side of the rectangular space? |
Author: | Fogmeister [ Wed Nov 21, 2012 12:46 pm ] | |||||||||
Post subject: | Re: Resizing an image and keeping aspect ratio | |||||||||
Exactly ![]() So if you have an image of size 1000x500 and I give you a size to resize it of 100x100. Then the image will be 100x50 (i.e. scaled to 10% of the original size). |
Author: | finlay666 [ Wed Nov 21, 2012 12:50 pm ] |
Post subject: | Re: Resizing an image and keeping aspect ratio |
I've written a standard resizing library in C# before, it's easy enough to keep the aspect ratio, you just need to know when resizing if you want to:
If you have any specific questions about the dimensions/logic side of things let me know Simple logic process with a 800:600 original and a 100x60 space: get original ratio, calculate scale for x and y (so say 4:3 for x and 3:4 for y) Attempt to fit object in using first x dimension, so you would get a 100x75 image if you kept x so if image > bounds, revert to y to get a 80:60 image instead if you wanted to force the image to fit in the dimensions, otherwise fit to x instead of fit absolute ![]() |
Author: | Fogmeister [ Wed Nov 21, 2012 12:54 pm ] |
Post subject: | Re: Resizing an image and keeping aspect ratio |
Yeah, I've done them before too ![]() I think I was just surprised that the guy had no idea where to start with it. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |