GIMP: auto resize canvas size to image size
Copy the layer then use shift
+ ctrl
+ v
to create a new image from the copied layer.
You can use "Crop to Selection" to achieve this.
Make sure the image is selected. Right click anywhere on canvas and navigate to "Image" menu, In image menu select "Crop to Selection".
Hare's the result!