Skip to content

Instantly share code, notes, and snippets.

@iranjith4
Last active June 20, 2016 11:27
Show Gist options
  • Save iranjith4/35d02036b1a3f19879b8ecbfa5e3b25e to your computer and use it in GitHub Desktop.
Save iranjith4/35d02036b1a3f19879b8ecbfa5e3b25e to your computer and use it in GitHub Desktop.
corona SDK image
--Function to get the New Height for Given Width
function getNewHeight(image , newWidth)
local r = image.width / image.height --4
local newHeight = newWidth / r --5
return newHeight --6
end
--Function to get the New Width for Given Height
function getNewWidth(image , newHeight)
local r = image.width / image.height
local newWidth = newHeight * r
return newWidth
end
--Usage
function createAnImage()
local myImage = display.newImage("myImagesDirectory/MyImages.png") --1
-- Call this before you are setting the width of the image
myImage.height = getNewHeight(myImage, display.contentWidth * 0.90) --2
--Set the same width you used in the previous line
myImage.width = display.contentWidth * 0.90 --3
sceneGroup:insert(myImage)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment