【问题标题】:How convert from other format to png format when using file_get_contents method? [duplicate]使用 file_get_contents 方法时如何从其他格式转换为 png 格式? [复制]
【发布时间】:2011-12-06 02:32:36
【问题描述】:

可能重复:
Convert jpg image to gif, png & bmp format using PHP

我正在使用 file_get_contents 方法从 url 获取 JPEG 图像文件。如何将其转换为 PNG 文件?

【问题讨论】:

    标签: php format-conversion


    【解决方案1】:

    我假设你的意思是转换。

    您可以使用 GD 库,更具体地说是 imagepng() 函数

    http://php.net/manual/en/function.imagepng.php

    <?php
    $im = imagecreatefromjpeg($imageFileURL);
    header('Content-Type: image/png');
    imagepng($im);
    

    此页面将以 .png 格式输出图像。

    如果你用循环来堆积这个,你可以用

    保存文件
    <?php
    $im = imagecreatefromjpeg($imageFileURL);
    imagepng($im, 'filename.png');
    

    【讨论】:

      猜你喜欢
      • 2021-06-15
      • 1970-01-01
      • 2015-09-21
      • 2015-06-23
      • 2023-04-01
      • 2014-11-09
      • 1970-01-01
      • 2011-08-12
      • 2014-09-11
      相关资源
      最近更新 更多