PDA

View Full Version : Resize default image within safearea?


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

Guest
27th September 2004, 17:45
I found out that I missed som floats - now it's working - so here it is if anybody might need it - test with images lager than 720x576!

Tin2tin

# SafeSize will downsize an image until it is within a safearea
# defined by SafeW(idth) and SafeH(eight), but without
# loosing the original aspect ratio.
# By Tin2tin

function SafeSize(image, int SafeW, int SafeH, int fps)
{
a = ImageReader(image,0,1,fps,false)
h = int(Height(a) * (float(SafeW)/float(Width(a))))
a = (Width(a) > SafeW) ? a.LanczosResize(SafeW,h): a
w = int(width(a)* (float(SafeH)/float(Height(a))))
a = (Height(a) > SafeH) ? a.LanczosResize(w,SafeH): a
a = FlipVertical(a)# The image comes out flipped - flip it back!
return a
}

# Test:
image = "avitest.JPG"
SafeH = 576
SafeW = 720
fps = 25
b = SafeSize (image,SafeW,SafeH,fps)
b.Subtitle("Width: "+string(width(b))+" "+"Height: "+string(Height(b)))

Guest
28th September 2004, 01:35
BTW can any of you get Imagesequence plugin to load? I understand there has been some trouble with it in the past - and I can't get it to load... so what's your situation/solution?

Tin2tin

lamer_de
28th September 2004, 12:41
ImageReader is present in v2.52, it replaces WarpEnterprises' plugin.
Taken from the avisynth documaentation. So, Imagereader can do everything Imagesequence could do. Or what exactly is your concern with Imagereader? (because Imagesequence still works for me (tested 2 days ago out of coincidence because I recyled an old script, but changed it to imagereader because I assume it's faster(??))

CU,
lamer_de