Hello friends i have an issue with endroid/qrcode libarary i created custom page template and the function .getContentType(); return the link of the page, and insert it into the img src, instead return the path of the actual image path that was created, i will glad for some helps, and advice’s, thanks appreciate it so much :-)
This is my code, out side of wordpress it works perfectly but when i put it in a custom page template or cpt template the function above return the wrong path..

<?php
include WP_CONTENT_DIR .'/endroid_qrcode/src/QrCode.php';

use EndroidQrCodeQrCode;


$qr = new QrCode();

$qr
->setText('http://www.solutions.com')
->setSize(200)
->setLabel('Scan the code', 16, __DIR__.'/../font/open_sans.ttf')
->setPadding(10)
->setErrorCorrection('high')
->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0])
->setBackgroundColor(['r' => 240, 'g' => 230, 'b' => 255, 'a' => 0])
->setLabel('Scan Me For Info')
->setLabelFontSize(16)
->setPadding(10)
->setImageType(QrCode::IMAGE_TYPE_PNG);
//->setLogoSize(98)
//->setLogo('logo/logo_tetrom.PNG')



$qr->render();

// save it to a file
$qr->save('wp-content/endroid_qrcode/generated_qr/qrcode_new.png');

// now we can directly output the qrcode


header('Content-Type: '.$qr->getContentType());
?>

as u can see the img src is the link to the page instead the file path,
($qr->save(‘wp-content/endroid_qrcode/generated_qr/qrcode_new.png’);)
the file was created, but the src in the img tag is generated the wrong way, what am i doing wrong?

output in the browser

Read more here: Endroid/Qrcode library with wordpress


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: