Log in

View Full Version : Alternative way to get images 2


xiaomickey
31st May 2006, 03:40
learn from http://forum.doom9.org/showthread.php?t=108818

i change it like this

temp = Photo("1.jpg")
c = temp

last=c

ImageWriter("G:\", start = 0, type = "jpg", info = true)

function Photo(string image)
{
t = ImageSource(image, end = 0, use_DevIL=true)
x = t.width
y = t.height
m = 0
n = 0

t = (x > 640) ? t.Addborders(0, ((x-640)/2)/4*3, 0, ((x-640)/2)/4*3, 0) : t.Addborders((640-x)/2, 0, (640-x)/2, 0, 0)

t = (y > 480) ? t.Addborders(((y-480)/2)/3*4, 0, ((y-480)/2)/3*4, 0, 0) : t.Addborders(0, (480-y)/2, 0, (480-y)/2, 0)

t = t.ConvertToRGB32().BilinearResize(640,480)

return t
}

it works well

but it do not fit the picture width > 640 && height > 480


then i change like this

temp = Photo("1.jpg")
c = temp

last=c

ImageWriter("G:\", start = 0, type = "jpg", info = true)

function Photo(string image)
{
t = ImageSource(image, end = 0, use_DevIL=true)
x = t.width
y = t.height

t = (x/4*3 > y) ? t.Addborders(0, (x/4*3-y)/2, 0, (y/3*4-x)/2, 50) : t.Addborders((y/3*4-x)/2, 0, (y/3*4-x)/2, 0, 50)

t = t.ConvertToRGB32().Lanczos4Resize(640,480)

return t
}


but strangely it doesnt work i dont know why :(



and ..... sorry for my poor english..... :o

IanB
31st May 2006, 04:42
x/4*3 is Int(x/4)*3, you probably want (x*3 > y*4)

Also look at these functionsint=Round(float)
int=Ceil(float)
int=Floor(float)
int=Int(float)to control how you round/truncate your calculated border integer parameters.

Also resize the images first, add the borders last. Resizing with the borders will blur the boundary of the border (unless you want blurred borders :) )

Also posting error messages and descriptions of undesired behaviour helps diagnose problems. "It doesn't work" relies on the mystic arts to devine your problem, which have a bad track record for accuracy.