Echoing a variable comes out with lots of white space

To expand on @Tom J Nowell’s comment, any whitespace after ?> and before <?php will get output, so if you are adding an alt tag you need to make there there’s no extra white space outside the <?php ?>. Here’s an example, and I’ve simplified your code a bit as you can do that in one command:

<img src="..." alt="<?php echo trim(get_post_meta(get_post_thumbnail_id(), '_wp_attachment_image_alt', true)); ?>">

If you need more help it’s useful to put the whole bit of code you’re using in your question