Skip to content

Instantly share code, notes, and snippets.

@mgdm
Created December 17, 2011 19:11
Show Gist options
  • Save mgdm/1491089 to your computer and use it in GitHub Desktop.
Save mgdm/1491089 to your computer and use it in GitHub Desktop.
RSVG with scaling
<?php
$width = $height = 1000;
if (isset($_GET['width'])) {
$width = (int) $_GET['width'];
}
if (isset($_GET['height'])) {
$height = (int) $_GET['height'];
}
header("Content-Type: image/png");
$r = Rsvg::createFromFile('karate.svg');
$dimensions = $r->getDimensions();
$s = new CairoImageSurface(CairoFormat::ARGB32, $width, $height);
$c = new CairoContext($s);
$c->scale($width / $dimensions['width'], $height / $dimensions['height']);
$r->render($c);
$s->writeToPng("php://output");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment