Log in

View Full Version : Even check. What I'm wrong


dplaton
13th July 2005, 13:59
I want to resize according to the size of the still
I have a 419x311 still
The final size is 719x575 and not 720x576
What I'm wrong?

Here is the code


a = "E:\baie\La_baie_1.tif"

# size 413x311
a = ImageReader (a , start, end, 25).ResizeDupaCaz ()

return a

Function ResizeDupaCaz ( clip c ) {

#With size to resize
Wsize = 672

#Test if clip size < Wsize NO then resize
WResize = (Width(c) > Wsize) ? Wsize : Width(c)

#set the Height resize according to Wresize
HResize = Round(Height(c) * WResize/Width(c))

#even Height check and adjust
HResize = (HResize/2 == int(HResize/2)) ? HResize : (HResize-1)

#resize down if is the case
c = c.BilinearResize (WResize, HResize)

#the case With clip < Wresize

#even With check and adjust
cutW = (Width(c)/2 == (Round(Width(c)/2))) ? 0 : 1

#Height cutting value if Height > 576
cutH = Height(c) - 576

#adjust Height cutting value if Height < 576
cutH = (cutH <= 0) ? 0 : cutH

# even Height check and adjust
cutH = (cutH/2 == Round(cutH/2)) ? 0 : (cutH+1)

c = c.Crop(0, cutH/2, cutW, cutH/2)

borderW = 720 - Width(c)

borderH = 576 - Height(c)

AddBorders (c, borderW/2, borderH/2, borderW/2, borderH/2)
return last
}

dplaton
13th July 2005, 14:08
Sorry for posting.
I'm cutting none.
I must to work around.

dplaton
13th July 2005, 14:12
No, I cheked only Height.
But why With is not cuted?

stickboy
14th July 2005, 04:27
[code[HResize/2 == int(HResize/2)
cutW = (Width(c)/2 == (Round(Width(c)/2))) ? 0 : 1[/code]That won't work; those expressions will always be true, because HResize and Width(c) are ints, and an int divided by an int is also an int and will be truncated automatically. For example, 3/2 = 1 and not 1.5.

If you want to check if a value is even, you should use:x % 2 == 0

I only skimmed over your code, so I'm not sure if any of the other logic is correct or not. Overall it looks more complicated than it ought to be.

dplaton
14th July 2005, 08:52
thanks
Yes is more complicated than should be.
But I'll be back

dplaton
14th July 2005, 11:22
new code


Function ResizeUponCase ( clip c ) {

#With size to resize
Wsize = 672

#Test if clip size < Wsize NO then resize
WResize = (Width(c) > Wsize) ? Wsize : Width(c)

#set the Height resize according to Wresize
HResize = Round(Height(c) * WResize/Width(c))

#resize down if is the case
c = c.BilinearResize (WResize, HResize)

#the case With clip < Wresize

#even With adjust
EvenW = int(Width(c)/2)*2
cutW = EvenW - Width(c)

#evenadjust Height cutting value if Height < 576
NewH = (Height(c)>576) ? (Height(c)-576) : int(Height(c)/2)*2
cutH = Height(c) - NewH

c = c.Crop(0, cutH, cutW, 0)

#final size 720x576
borderW = 720 - Width(c)

borderH = 576 - Height(c)

AddBorders(c, borderW/2, borderH/2, borderW/2, borderH/2)
return last
}

dplaton
14th July 2005, 13:12
final

Function ResizeUponCase ( clip c ) {

#With size to resize
Wsize = 672

#Test if clip size < Wsize NO then resize
WResize = (Width(c) > Wsize) ? Wsize : Width(c)

#set the Height resize according to Wresize
HResize = Round(Height(c) * WResize/Width(c))

#resize down if is the case
c = c.BilinearResize (WResize, HResize)

#the case With clip < Wresize

#even With adjust
EvenW = int(Width(c)/2)*2
cutW = EvenW - Width(c)

#evenadjust Height cutting value if Height < 576
mare = Height(c)-576
mic = Height(c)-int(Height(c)/2)*2
cutH = (Height(c)>576) ? mare : mic

c = c.Crop(0, cutH, cutW, 0)

#final size 720x576
borderW = 720 - Width(c)

borderH = 576 - Height(c)

AddBorders(c, borderW/2, borderH/2, borderW/2, borderH/2)
return last
}

dplaton
15th July 2005, 09:42
One more time.
This is a part for a slide show script that resize larger images to a TV visible one,
and add border to a smaller one.

Wilbert
15th July 2005, 09:44
So, does it work?

dplaton
15th July 2005, 09:49
Yes, it works.
I tested with smaller and larger still images and works.