如何保存php脚本生成的图像


How to save an image generated by a php script?

我有一个生成条形码的第三方php文件,称为barcode.php。

当我想生成一个新的条形码时,我会调用这个脚本,如下所示:

<img alt="testing" src="barcode.php?text=455555442233&codetype=Code25" />

有没有一种简单的方法可以在不修改barcode.php脚本的情况下将生成的图像保存到服务器上?

$file = 'barcode.jpg'; //file name to write to include location if needed
$current = file_get_contents('http://yoursite.com/barcode.php?text=455555442233&codetype=Code25');//read the created file
file_put_contents($file, $current);//write it

在这里使用外部url可能是次优的,这取决于