How can I scale up an SVG and save as PNG, with PHP without losing quality?

自作多情 提交于 2019-12-08 14:36:23

For option A:

If the svg expects the coordinate system to be whatever it was when it was created (read: the original width/height), then you will need to add a viewBox attribute (use 0 0 originalwidth originalheight). Then when you set new width and height attributes the svg should rescale itself properly to the new size.

I have achived this similar thing using 'batik' library.

I have specifed 'Area of Interest' which need to be converted to Png. here's what i have done.

    public function makeSvgtoPngImages() {
     $tempSVG_filename = $user_folder_path . 'temp.svg';                   
     $tempSVG_handle = fopen($tempSVG_filename, 'w+');
     fwrite($tempSVG_handle, $user_svg_content);
     fclose($tempSVG_handle);

        $mimetype = 'image/png';
        $width =2000;
        $height=2000;                    
        $area_interest = '472,185,555,275'; 
      // in my case i am using area of interest is my viewBox                   

        $result = shell_exec('java  -jar /var/www/batik-1.7/batik-rasterizer.jar -m ' . $mimetype . ' -d ' . $outputfile . ' -w ' . $width . ' -h ' . $height . ' -a ' . $area_interest . ' ' . $tempSVG_filename . ' 2>&1');

         unlink($tempSVG_filename);


}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!