วิธีรับภาพในคอนโทรลเลอร์หรือผู้ช่วย ตัวอย่างเช่นเส้นทางของโฟลเดอร์รูปภาพ:
 /app/code/Nitesh/Module/view/frontend/web/images
 /app/code/Nitesh/Module/view/frontend/web/images/image.pngวิธีรับภาพในคอนโทรลเลอร์หรือผู้ช่วย ตัวอย่างเช่นเส้นทางของโฟลเดอร์รูปภาพ:
 /app/code/Nitesh/Module/view/frontend/web/images
 /app/code/Nitesh/Module/view/frontend/web/images/image.pngคำตอบ:
ใช้โค้ดด้านล่างเพื่อรับ URL รูปภาพ view
<img src="<?php echo $this->getViewFileUrl('Vendor_Module::images/image.png'); ?>" />UPDATE:
<?php echo $block->getViewFileUrl('images/demo.jpg'); ?>ในการรับเส้นทางภาพในตัวช่วยหรือตัวควบคุมคุณต้องใช้
use Magento\Framework\View\Asset\Repository;
use Magento\Framework\App\RequestInterface; // for $this->requestในไฟล์ของคุณ 
เมื่อคุณเพิ่มที่เก็บและสร้างออบเจกต์assetRepo& requestแล้วให้เรียกใช้เส้นทางภาพพร้อมฟังก์ชัน
$params = array('_secure' => $this->request->isSecure());
$this->assetRepo->getUrlWithParams('Nitesh_Module::images/image.png', $params);อ้างถึงvendor\magento\module-payment\Model\CcConfig.php::getViewFileUrl($fileId, array $params = [])ฟังก์ชั่น
แก้ไข
ในการขอเส้นทางภาพที่ถูกต้องสำหรับสคริปต์การตั้งค่าการโทร API และ Cronjobs คุณจะต้องเพิ่มการจำลองด้านล่างเพื่อรับเส้นทางภาพที่ถูกต้อง
public function __construct(
    \Magento\Framework\View\Asset\Repository $assetRepo,
    \Magento\Framework\App\RequestInterface $request,
    \Magento\Store\Model\App\Emulation $appEmulation
)
{
    $this->assetRepo = $assetRepo;
    $this->request = $request;
    $this->appEmulation = $appEmulation;
}
public FunctionName($param){
    $this->appEmulation->startEnvironmentEmulation($storeId, \Magento\Framework\App\Area::AREA_FRONTEND, true);
    $params = array('_secure' => $this->request->isSecure());
    $this->assetRepo->getUrlWithParams('Nitesh_Module::images/image.png', $params);
    $this->appEmulation->stopEnvironmentEmulation();
}การอ้างอิง: https://magento.stackexchange.com/a/297121/2443