php image保存到目录并保存为pdf

Im using http://www.ashberg.de/php-barcode/ scripts to generate a barcode. I now need to import the barcode into a PDF from html. (Im using html2pdf_v4.03 for html -> pdf)

<div style=" display:inline;"><img id='barcode' alt='barcode' src="scripts/barcode/barcode.php?mode=jpg"  /></div>

works, but when I import it to PDF it errors. So I decided to try generate the barcode and save it to a dir as an img and refrence it in the html I then convert to PDF.

So I tried

file_put_contents('scripts/barcode.jpg', file_get_contents('scripts/barcode/barcode.php?mode=jpg'));

and I get failed to open stream: error

if i try

file_put_contents('scripts/barcode.jpg', file_get_contents('scripts/barcode/barcode.php'));

It runs but the image file it creates is not readable/ broken.

Please assist?

Write full url (http://domain.com/scripts/barcode/barcode.php) instead of scripts/barcode/barcode.php. Probably its opens local php file when you use file_get_contents()