You can use this query to get the image id of the cover image (image displayed in category view) for a product:
SELECT id_image FROM ps_image WHERE cover = 1 AND id_product = $idProduct
Then you can generate the image path with the following code:
$imgPath = 'img/p/';
for ($i = 0; $i < strlen($idImage); $i++) {
$imgPath .= $idImage[$i] . '/';
}
$imgPath .= $idImage . '.jpg';
If you want to get the image id of the default thumbnail displayed in the product view then you can use this query:
SELECT id_image FROM ps_image WHERE position = 1 AND id_product = $idProduct