I made this crop function you could use. In example at bottom I’m using a red rect, just use display.newImage instead of the rect.
[lua]
local function crop(photo, newFileName)
– End size we want
local endWidth = 256
local endHeight = 256
local tempGroup = display.newGroup()
photo.x = display.contentCenterX
photo.y = display.contentCenterY
tempGroup:insert(photo)
– Find the bigger scale out of widht or height so it will fill in the crop
local scale = math.max(endWidth / photo.width, endHeight / photo.height)
photo:scale(scale, scale)
– This object will be used as screen capture boundaries object
local cropArea = display.newRect(display.contentCenterX, display.contentCenterY, endWidth, endHeight)
cropArea.x = display.contentCenterX
cropArea.y = display.contentCenterY
cropArea : setReferencePoint(display.CenterReferencePoint)
cropArea.alpha = 0.0
tempGroup:insert(cropArea)
– Now capture the crop area which the user image will be underneith
local myCaptureImage = display.captureBounds(cropArea.contentBounds)
display.save(myCaptureImage, newFileName)
--myCaptureImage:removeSelf() – Remove captured image
--myCaptureImage = nil
tempGroup:removeSelf()
tempGroup = nil
end
local photo = display.newRect(10,10,100,400)
photo:setFillColor(255,0,0)
– Put cropped photo into documents directory
crop(photo, “cropped.png”)
[/lua]