To expand on Rob’s answer, sometimes you don’t know the width/height of an image beforehand (e.g. a downloaded image). however it’s likely that you will know how big you want the image to appear (based on the rest of your UI).
For those circumstances, I tend to use newImage and then scale the image until it fits a size that I have defined:
local myImage = display.newImage("mydownloadedimage.png") --let's assume that my UI has space for a rectangular image which is 512\*256 local targetWidth, targetHeight = 512, 256 --this is the variable we will use to scale the whole image --we want to scale the width and height by the same value, to keep the aspect ratio correct local scaleValue = 1 --set the scale: we want to use the image's largest dimension to fit it to size --e.g. if the image is tall rather than wide we want to scale it until it fits within the height we have allowed if myImage.width \> myImage.height then --if image is wide then use the width to determine scale scaleValue = targetWidth / myImage.width else --if it is tall (or square) then use the height scaleValue = targetHeight / myImage.height end --apply the scale to the image myImage.xScale, myImage.yScale = scaleValue, scaleValue
I just did this quickly, so apologies if there are any typos.