You’re in luck as we needed to do exactly that for Forever Lost and Forever Lost Camera. The lib we created for that is soon going to be released as a GG Lib but until then here is the function you will want:
[lua]function scaleToFit( image, width, height )
local baseSize = { width = width or display.contentWidth * display.contentScaleX, height = height or display.contentHeight * display.contentScaleY }
image.xScale = baseSize.width / image.contentWidth
image.yScale = baseSize.height / image.contentHeight
image.x = display.contentCenterX
image.y = display.contentCenterY
end[/lua]
You will probably need to adjust things depending on your use case but the actual core part of the function will work for you.
You can then do things like this to create a small thubmnail:
[lua]scaleToFit( largeImage, 50, 30 )[/lua]
Or full screen:
[lua]scaleToFit( largeImage )[/lua]
Or largeish:
[lua]scaleToFit( largeImage, 250, 200 )[/lua] [import]uid: 119420 topic_id: 33390 reply_id: 132615[/import]