scaleじゃなくて
layer.resize(img.width, img.height, (img.width - layer.width) / 2,(img.height - layer.height) / 2)
かな