Saving images to a size... How best to handle this?

If you have find a solution, we would be be very grateful. We have try so many combination to get it right, but it is impossible to get the same value depending on the device.

I also have the same issue and am very interested in the solution!

On our side, we have finally come up with a method that is outputting the same image size regardless of the device, regardless of the original image size and regardless of our config file with the following:

local function cropImage(photo, newFileName, cropW, cropH)

    

    – adjust width and height of the resulting image

    local endWidth  = cropW * display.contentScaleX

    local endHeight = cropH * display.contentScaleY

    

    – set the masking container

    local tempGroup = display.newSnapshot(endWidth, endHeight )

    tempGroup.x = 0

    tempGroup.y = 0

    tempGroup.anchorX = 0

    tempGroup.anchorY = 0

    

    – Define a solid color background, in case the final image is

    – smaller than the cropping output

    local whiteRc = display.newRect( 0, 0, endWidth, endHeight )

    tempGroup.group:insert(whiteRc)

    whiteRc.anchorX = 0.5

    whiteRc.anchorY = 0.5

    whiteRc:setFillColor( 1,1,1 )

    

    – insert the photo

    tempGroup.group:insert(photo)

    

    – scale the photo to your need.

    local scale = math.max(endWidth / photo.width, endHeight / photo.height) 

    photo:scale(scale, scale)

    

    – center the photo inside the container or position it

    – the way you want inside the container area. In our case

    – we center it.

    photo.x = 0

    photo.y = 0

    photo.anchorX = 0.5

    photo.anchorY = 0.5

    – save the cropped image

    display.save( tempGroup, { filename = newFileName, baseDir = system.TemporaryDirectory, isFullResolution = true } )

    – clean up the mess

    tempGroup:removeSelf()

    tempGroup = nil

end

Jedi,

Thank You! I will give it a shot today!

Worked like a champ!

Thanks!