Try out with the below example code:
<html>
<?php
$dir = $_GET["input"];
$img = imagecreatefrompng("./$dir/subdir/images/sample.png");
?>
<body>
<img src="???" alt="sample image" />
</body>
</html>
If only one image:
<img src="<?= $img ?>" alt="sample image" />
If loads of images, use an array.
I have an image in each directory at ./$dir/subdir/images/sample.png
Hope this helps.