You're trying to display the raw bytes of an image inline within an HTML file. That won't work.
You'll either need a separate endpoint to generate the thumbnail, and reference that as your image source:
<img src="getPdfThumbnail.php">
Or convert the data to Base64, and use a
data:
URI:
echo '<img src="data:image/jpeg;base64,' . base64_encode($im) . '">';
Data URLs - HTTP | MDN[
^]