【问题标题】:Push svg to the browser in php [closed]在php中将svg推送到浏览器[关闭]
【发布时间】:2015-06-18 21:46:34
【问题描述】:

使用png,

header('Content-Type: image/png');
imagepng(imagecreatefrompng($pathToPng));

使用 svg,

header('Content-Type: image/svg+xml');
// ???

【问题讨论】:

  • @CamilStaps 我有没有提到我想将 png 转换为 svg ?
  • 如果你不问问题,很难猜出你想要什么。您似乎有一个 PNG 并且想要输出一个 SVG。所以,是的,您想将 PNG 转换为 SVG。否则,请编辑您的问题并澄清。

标签: php image svg header png


【解决方案1】:

由于很难从社区获得帮助,我制作了一个临时工作脚本。希望对其他人有所帮助。

$imgInfo = pathinfo($_GET['img']);
$imgRelativePath = $imgInfo['dirname'];
$imgName = urlencode($imgInfo['filename']);
$imgExtension = str_replace(' ', '+', $imgInfo['extension']);

switch ($imgExtension) {
case 'svg+xml':
    set_header('image/svg+xml');
    break;
case 'png':
    set_header('image/png');
    break;
}



$imgPath = sprintf(
    '%s/%s.%s',
    $imgRelativePath,
    $imgName,
    $imgExtension);


if ($file = fopen($imgPath,'r')) {

    while (!feof($file)) {
        print fread($file, 2048);
    }
}



function set_header ($contentType) {
    header("Content-Type: $contentType");
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-05
    • 2018-01-24
    • 1970-01-01
    • 1970-01-01
    • 2019-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多