By Alexander Toporkov, web developer at Email Soldiers
The graphic format SVG (Scalable Vector Graphics) is the most widespread vector graphics format today, which compares favorably with raster, first of all, the ability to scale and transform images. But sometimes you need to convert SVG to PNG (Portable Network Graphics) - a bitmap graphics format.
Today's imaging requirements are high. They should look pretty everywhere, from the phone to the huge screen. You can't do without vector graphics: logos, diagrams, illustrations are best done in vector - this becomes obvious if you compare different formats of the same image when scaling:
Why convert SVG to PNG
The SVG format is old by the standards of information technology. Ten years have passed since the release of the first version in 2001 to the current version of August 16, 2011. SVG is supported by all browsers, and it would seem that the entire Internet should already switch to vector graphics. But there are still many restrictions on the use of SVG.
For example, such:
- SVG files don't show up in most email clients - there is good research on this topic.
- RSS, YML (Yandex Market Language) Google Merchant SVG- — .
- SVG OpenGraph ( HTML- , ). , : Facebook SVG.
, — , . , .
— , , . , , , , , .
( ) SVG-: . SVG PNG — YML-, Mindbox , .
SVG PNG — . SVG: , — . .
: PHP ImageMagick
ImageMagick — , Photoshop. PHP. PHP- Imagick, PHP.
SVG PNG :
<?php
$imagick = new Imagick();
$fp = fopen(‘image.svg’, ’rb’);
$imagick->readImageFile($fp);
$imagick->setImageFormat("png8«); //png8 — png c 8-
$imagick->writeImage(‘image.png’);
fclose($fp);
. , SVG ImageMagick , libmagickcore-6.q16-3-extra. , Debian Linux, .
:
sudo apt-get install libmagickcore-6.q16-3-extra
SVG. . , : , . , «».
, . ? , , $imagick->readImageFile, 5%. .
, , . , , .
ImageMagick - . / . - , ImageMagic .
: Node.js
PHP , , — JavaScript. Node.js.
SVG : PhantomJS, — Headless Chrome. , , Chrome-, . , , . , SVG , ( ). .
: , SVG PNG . , , — node.js.
, - . .
— . . .
— .
:
— , . PHP-. . .
ImageMagick.
<?php
$cline = ‘convert image.svg image.png’;
shell_exec($cline);
?>
ImageMagick , . , - ImageMagick, .
SVG. Inkscape. , , :
sudo apt-get install inkscape
:
<?php
$cline = inkscape -z --export-png=image.png image.svg’;
shell_exec($cline);
?>
: SVG .
<?php
$cline = inkscape -z --export-png=image.png -w 1000 image.svg’;
shell_exec($cline);
?>
: Inkscape , ImageMagick, SVG- PNG. . SVG- YML-: .
Inkspace ImageMagic .
, : Google, Facebook, Yandex. IT- SVG? , , .
, , 10 .