I am running ImageMagick from the command line, via PHP's exec() function. I need to convert an SVG image to PNG. Something like this:
exec('-convert image.svg image.png');
I need to get the contents of image.svg, and manipulate them before converting the file to PNG. Do I have to save the altered image.svg to a new file, or is there a way to write the PNG file from a string?
For example I would get the file into the $image variable like this:
$image = file_get_contents('image.svg');
Then I would manipulate $image, based on an outside input. How can I directly convert $image to a PNG image without having to save it first as an SVG image? Is that even possible?
Initilizing an image from a string intead of a file
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Initilizing an image from a string intead of a file
You can specify an image on the command line, but there is command line limits, and the file needs to be converted to base64.
See IM Examples. File handling, inline:
http://www.imagemagick.org/Usage/files/#inline
See IM Examples. File handling, inline:
http://www.imagemagick.org/Usage/files/#inline
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Initilizing an image from a string intead of a file
Thank you for the reply. It looks like my image is too large for that, so I'll just have to save it as a file and then have the script delete the file once the conversion is complete.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Initilizing an image from a string intead of a file
I don't know PHP, but it may allow piping, as in the command...
... where something has piped the SVG contents to stdout.
Code: Select all
convert - image.png
snibgo's IM pages: im.snibgo.com