Dimensions of resized images

Hi! This is quite easy, probably!

I am looking for a way to resize images that  changes the actual dimensions. Currently, I am using the code below, but when I ask for, for instance, the height of a scaled image, I only get the original height.

Can you suggest another way?

Cheers!

function newScaledImage(filename, settings, baseDirectory, left, top) local img = display.newImage(filename, baseDirectory or "", left, top) -- No settings if (settings.width == nil) and (settings.height == nil) then return img end -- Only one dimension specified if settings.width ~= nil then local ar = settings.width / img.width img.xScale = ar img.yScale = ar --print("ar = " .. ar .. " imgw = " .. img.width) else local ar = settings.height / img.height img.xScale = ar img.yScale = ar --print("ar = " .. ar .. " imgh = " .. img.height) end -- Width and height if (settings.width ~= nil) and (settings.height ~= nil) then local arx = settings.width / img.width local ary = settings.height / img.height img.xScale = arx img.yScale = ary end return img end

You can create an image using display.newImageRect to specify the size and it will change contentWidth when you scale it. If you are dynamically scaling and want the real pixel value then just divide by the screen scaling.

image.contentWidth / display.contentScaleX

if you are not getting the image to update its width with display.newImage then just multiple the two values.

image.contentWidth * image.xScale

You can create an image using display.newImageRect to specify the size and it will change contentWidth when you scale it. If you are dynamically scaling and want the real pixel value then just divide by the screen scaling.

image.contentWidth / display.contentScaleX

if you are not getting the image to update its width with display.newImage then just multiple the two values.

image.contentWidth * image.xScale