Help resizing UI at runtime

I have a frame, and then a child of that frame is a photo which is taken at runtime. I need to resize the frame to fit the photo. I’ve tried the content size fitter but it didn’t work or perhaps I’m not using it correctly. Can someone please tell me what components/anchors I need to apply to achieve what I want? Here is an image of it now, and I want the white frame to be snug around the image.

Click in the anchor button where you can set different predefined anchors, then press alt key and shift key and select the down right corner one

The aspect ratio fitter component alongside the code below has solved all my problems.

 Vector2 imageSize = new Vector2(GetComponent<Image>().sprite.texture.width,
                                        GetComponent<Image>().sprite.texture.height);
        float imageRatio = imageSize.x / imageSize.y;

        GetComponentInParent<AspectRatioFitter>().aspectRatio = imageRatio;