Modern answer to this question:
We have WP_Customize_Media_Control
control in WP since 4.2 that gives you the attachment id.
This answer was posted on I similar question.
You can see the documentation for WP_Customize_Media_Control
here.
Exemple of use:
$wp_customize->add_setting( 'my_menu_image' );
$wp_customize->add_control( new \WP_Customize_Media_Control(
$wp_customize,
'storms_menu_image_ctrl',
array(
'priority' => 10,
'mime_type' => 'image',
'settings' => 'my_menu_image',
'label' => __( 'Image on menu bar', 'my' ),
'section' => 'title_tagline',
)
) );
When retrieving the info, you can do this:
$image_id = get_theme_mod( "my_menu_image" );
if ( ! empty( $image_id ) ) {
$url = esc_url_raw( wp_get_attachment_url( $image_id ) );
$image_data = wp_get_attachment_metadata( $image_id );
$width = $image_data['width'];
$height = $image_data['height'];
}