【问题标题】:Saving PNG file created by Google Chart API保存由 Google Chart API 创建的 PNG 文件
【发布时间】:2018-09-25 10:57:23
【问题描述】:

使用 Google API 创建了一个二维码(是的,我知道它已弃用) 但是我似乎无法保存生成的图像。 如果我单击图像并尝试保存它只会保存一个 PHP 文件

有什么想法吗??

这里是代码

$data = isset($_GET['data']) ? $_GET['data'] : 'FGS Ingredients';
$size = isset($_GET['size']) ? $_GET['size'] : '300x300';
$logo = 'fgsqrcodelogo.png';
header('Content-type: image/png');
// Get QR Code image from Google Chart API
// http://code.google.com/apis/chart/infographics/docs/qr_codes.html
$QR = imagecreatefrompng('https://chart.googleapis.com/chart?cht=qr&chld=H|1&chs='.$size.'&chl='.urlencode($data));
if($logo !== FALSE){
    $logo = imagecreatefromstring(file_get_contents($logo));
    $QR_width = imagesx($QR);
    $QR_height = imagesy($QR);

    $logo_width = imagesx($logo);
    $logo_height = imagesy($logo);

    // Scale logo to fit in the QR Code
    $logo_qr_width = $QR_width/3;
    $scale = $logo_width/$logo_qr_width;
    $logo_qr_height = $logo_height/$scale;

    imagecopyresampled($QR, $logo, $QR_width/3, $QR_height/3, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);
}
imagepng($QR);
imagedestroy($QR);
file_put_contents('myfile.png',$QR);

【问题讨论】:

    标签: php google-api imagecreatefrompng


    【解决方案1】:

    解决了... 刚刚添加

    $name = str_replace(' ','-',$data);
    $save = "". strtolower($name) .".png";
    then changed to imagepng($QR,$save);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-13
      • 1970-01-01
      • 1970-01-01
      • 2020-10-12
      • 2016-12-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多