Guest
26th September 2004, 19:06
Hi,
I'm trying to figure out how to resize a default image within a max width & height, but without loosing the original aspect ratio and I simply can't get it to work:
# SafeSize downsize image until it's smaller than max height & width.
# Without loosing the original aspect ratio
function SafeSize(image, int ImageMaxW, int ImageMaxH, int fps)
{
a = ImageReader(image,0,1,fps,false)
h = int(Height(a) * float(ImageMaxW/Width(a) ) )+5 #+5 is to avoid errors
a = (Width(a) > ImageMaxW) ? a.LanczosResize(ImageMaxW,h): a
w = int((width(a)* float(Height(a)/ImageMaxH)))+5 #+5 is to avoid errors
a = (Height(a) > ImageMaxH) ? a.LanczosResize(w,ImageMaxH): a
a = FlipVertical(a)# dunno why the resize flips the image - so it must be flipped back?
return a
}
# Test:
image = "imagetest.JPG"
ImageMaxH = 576
ImageMaxW = 720
fps = 25
SafeSize (image,ImageMaxW,ImageMaxH,fps)
I would like it to downsize the image to either the max width or max height but only if one of them is bigger than the ImageMaxH/ImageMaxW values.
I hope someone of you guys can help me out here. :confused:
Tin2Tin
I'm trying to figure out how to resize a default image within a max width & height, but without loosing the original aspect ratio and I simply can't get it to work:
# SafeSize downsize image until it's smaller than max height & width.
# Without loosing the original aspect ratio
function SafeSize(image, int ImageMaxW, int ImageMaxH, int fps)
{
a = ImageReader(image,0,1,fps,false)
h = int(Height(a) * float(ImageMaxW/Width(a) ) )+5 #+5 is to avoid errors
a = (Width(a) > ImageMaxW) ? a.LanczosResize(ImageMaxW,h): a
w = int((width(a)* float(Height(a)/ImageMaxH)))+5 #+5 is to avoid errors
a = (Height(a) > ImageMaxH) ? a.LanczosResize(w,ImageMaxH): a
a = FlipVertical(a)# dunno why the resize flips the image - so it must be flipped back?
return a
}
# Test:
image = "imagetest.JPG"
ImageMaxH = 576
ImageMaxW = 720
fps = 25
SafeSize (image,ImageMaxW,ImageMaxH,fps)
I would like it to downsize the image to either the max width or max height but only if one of them is bigger than the ImageMaxH/ImageMaxW values.
I hope someone of you guys can help me out here. :confused:
Tin2Tin