Resize with minWidth and minHeight
Closed this issue · 9 comments
Is there any function that resizes an image preserving aspect ratio and has result dimentions not less than specified? (like Resize To Fit but with min. dimenstions)
Perhaps there is a combination of steps that can anchieve what you are
looking for. If you could give me a more concrete example so that I am sure
I understand the problem (perhaps with an example image) and I would be
glad to help figure it out.
On Sat, Jan 19, 2013 at 5:24 AM, nicknameforever
notifications@github.comwrote:
Is there any function that resizes an image preserving aspect ratio and
has result dimentions not less than specified? (like Resize To Fit but with
min. dimenstions)—
Reply to this email directly or view it on GitHubhttps://github.com/blitline-dev/blitline/issues/4.
I believe this is a common problem to generate thumbnails for images. For example like in facebook, it doesn't generate thumbnails with fixed size, it preserves aspect ratio and hides the rest. Example:
- source image 800*600
- box for the thumbnail 100*50
- result image 100*75
In this particular example, I think you can use resize_to_fit with just a
width. (No height specified) So for example here:
http://www.blitline.com/docs/gist_runner?gist_id=4573999
You can see that the original source is 800x600 and we only set the width
to be 100, the other will be auto sized to meet that width=100 requirement
(and thus to 75px height)
Then, if we wanted to push it into 50px height, you could then
resize_to_fill with 100x50 to make it fit in the box.
Like here:
http://www.blitline.com/docs/gist_runner?gist_id=4574087
Is this useful?
On Sat, Jan 19, 2013 at 9:56 AM, nicknameforever
notifications@github.comwrote:
I believe this is a common problem to generate thumbnails for images. For
example like in facebook, it doesn't generate thumbnails with fixed size,
it preserves aspect ratio and hides the rest. Example:
source image 800*600
box for the thumbnail 100*50
result image 100*75
—
Reply to this email directly or view it on GitHubhttps://github.com/blitline-dev/blitline/issues/4#issuecomment-12458325.
Thanks, but the point is that the result image should not be cropped on any step. Would it be possible to introduce a new function "Resize to Wrap" like the following?
input: image, min_width, min_height
width, height = extractDimensions(image)
aspect_src = width / height
aspect_dst = min_width / min_height
if aspect_src >= aspect_dst
w = min_width * aspect_src / aspect_dst
h = min_height
else
w = min_width
h = min_height * aspect_dst / aspect_src
end
return Resize(image, w, h)
We can do this.
We will try to get it out with our next push, which should be early this
week. I will notify you when we have it in place.
On Sat, Jan 19, 2013 at 10:47 AM, nicknameforever
notifications@github.comwrote:
Thanks, but the point is that the result image should not be cropped on
any step. Would it be possible to introduce a new function "Resize to Wrap"
like the following?input: image, min_width, min_height
width, height = extractDimensions(image)
aspect_src = width / heightaspect_dst = min_width / min_height
if aspect_src >= aspect_dst
w = min_width * aspect_src / aspect_dst
h = min_height
else
w = min_width
h = min_height * aspect_dst / aspect_src
endreturn Resize(image, w, h)
—
Reply to this email directly or view it on GitHubhttps://github.com/blitline-dev/blitline/issues/4#issuecomment-12459127.
Great, thank you!
This functionality should now be in place. We haven't updated our docs to
show it, but you can see an example of it here. It has the same signature
as "resize_to_fit" but is named "resize_to_fit_with_wrap"
We have implemented is as per your code, and you can try it at:
http://www.blitline.com/docs/gist_runner?gist_id=4596764
Hope this helps!
On Sun, Jan 20, 2013 at 1:09 PM, nicknameforever
notifications@github.comwrote:
Great, thank you!
—
Reply to this email directly or view it on GitHubhttps://github.com/blitline-dev/blitline/issues/4#issuecomment-12477499.
It looks good but not quite. This test case fails:
src image: 320_480
box to wrap: 200_70
result of my code: 200_300 (the same aspect ratio)
result of your function: 200_210 (aspect ratio broken)
Calculation: h = min_height * aspect_dst / aspect_src = 70 * (200/70) / (320/480) = 300
You are absolutely right. We had an integer truncation problem (instead of
float), so the math got squirrely.
We have pushed the fix. You should be able to see it working properly now
with an example at:
http://www.blitline.com/docs/gist_runner?gist_id=4598319
On Tue, Jan 22, 2013 at 11:42 AM, nicknameforever
notifications@github.comwrote:
It looks good but not quite. This test case fails:
src image: 320_480
box to wrap: 200_70result of my code: 200_300 (the same aspect ratio)
result of your function: 200_210 (aspect ratio broken)Calculation: h = min_height * aspect_dst / aspect_src = 70 * (200/70) /
(320/480) = 300—
Reply to this email directly or view it on GitHubhttps://github.com/blitline-dev/blitline/issues/4#issuecomment-12562136.