Could you please explain to me what I need to do in the "step 3"?
Say sprite is supposed to be no bigger than 256x256, use a couple of variables/globals to store new width and height based on calculation that sets the biggest side to 256 and the other to a proportionate size, then apply those to the sprite
newWidth = sprite.Width >= sprite.Height ? 256 : (sprite.Width/sprite.Height)*256
newHeight = sprite.Height >= sprite.Width ? 256 : (sprite.Height/sprite.Width)*256
sprite.Width = newWidth
sprite.Height = newHeight
EDIT: Did a quick example capx (r233)