Reputation: 21
There's a need to transform .svg files and save em either in .svg or jpeg format. The problems with ImageMagick is that it saves transformed files on white background and I deadly need it on transparent.
Any suggestions with other tools or clear php? Would really appreciate it.
Upvotes: 2
Views: 1164
Reputation: 18175
The right ImageMagick command should be:
convert -background none somefile.svg somefile.png
You should use PNG or GIF as file format, because JPEG doesn't support transparency.
To use it in PHP:
<?php
$svg_file_name = "somefile.svg";
$png_file_name = "somefile.png;
system("convert -background none $svg_file_name $png_file_name");
?>
Upvotes: 4
Reputation: 9927
You can't do transparency with JPEG, but here's how to save an SVG as a PNG with a transparent background...
$image = new Imagick();
$image->setBackgroundColor(new ImagickPixel('transparent'));
$image->readImage('somefile.svg');
// ... do any image manipulation you need to here ...
$image->setImageFormat('png32');
$image->writeImage('somefile.png');
Upvotes: 0
Reputation: 11087
I doubt you can transform SVG files easily from within php. SVG files are basically XML files, and the standard is public, so anyone can make a converter...
I'd go for the external tool, it's easier and faster than processing from within a scripted language, and a lot safer when the author of the script dosen't actually know how to find out the command line switches for an application, and that JPEG files does not support transparency:)
go for convert -background none somefile.svg somefile.png
as Jens said...
Upvotes: 0