-3

using png,

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

using svg,

header('Content-Type: image/svg+xml');
// ???
vdegenne
  • 12,272
  • 14
  • 80
  • 106
  • possible duplicate of [Convert JPG/PNG to SVG format using PHP](http://stackoverflow.com/questions/20517497/convert-jpg-png-to-svg-format-using-php) –  Apr 13 '15 at 14:28
  • @CamilStaps Did I mention I want to convert png to svg ? – vdegenne Apr 13 '15 at 14:29
  • It's hard to guess what you want if you don't ask a question. You seem to have a PNG and want to output an SVG. So, yes, you want to convert PNG to SVG. Otherwise, edit your question and clarify. –  Apr 13 '15 at 14:32

1 Answers1

1

As it was hard to get help from the community, I made a temporary working-script. hope it helps others.

$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");
}
vdegenne
  • 12,272
  • 14
  • 80
  • 106