Magento – How to get image path in magento 2 module

imagemagento-2.1magento2

My image path is

app/code/Vendor/Module/frontend/web/images/tool/test.png

How to get this image path?

Please see screenshot:

screenshot

Best Answer

You will get image by below code . I hope you have image name which you want there.

public function __construct(

    \Magento\Framework\View\Asset\Repository $assetRepo,
){
    $this->assetRepo = $assetRepo;
}

public function testImageUrl(){
    $url =  $this->assetRepo->getUrl("Namespace_Module::image.png");;
    return $url;
}
Related Topic