【问题标题】:imagecreatefromstring can get url or file?imagecreatefromstring 可以获取 url 或文件吗?
【发布时间】:2014-06-30 15:42:47
【问题描述】:

我有一张带有此 src 属性 http://myhost.lan/images/log/parts/bg/001.png 的图像,我可以将此网址作为字符串传递给 imagecreatefromstring 函数吗?到底是什么意思 imagecreatefromstring — Create a new image from the image stream in the string 在 imagecreatefromstring 手册中?

【问题讨论】:

    标签: php gd


    【解决方案1】:

    是的,你可以这样做:

    $src = "http://myhost.lan/images/log/parts/bg/001.png";
    $image = imagecreatefromstring(file_get_contents($src));
    

    【讨论】:

      【解决方案2】:

      由于您尝试加载的图像是.png 图像类型,因此您可以这样做:

      header("Content-Type: image/png");
      $im = imagecreatefrompng('http://myhost.lan/images/log/parts/bg/001.png');
      imagepng($im);
      imagedestroy($im);
      exit();
      

      阅读手册:

      【讨论】:

      • 我想知道图像流的确切含义是什么??
      猜你喜欢
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 2011-02-20
      • 2018-07-02
      • 1970-01-01
      • 2020-05-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多