I've been struggling with resize coding for more than three weeks. Still cannot get the correct outfile. Instead it shows 'twisted image' as shown below (image viewer zoom fit).
There must be something wrong with my padding or positioning. But I cannot pinpoint which line(s) are causing this. Headers have been confirmed right using the peek function. Related portion of my code is shown below. If anyone can help me out, I would very much appreciate it.