![]() ![]() Unlike SVG images, raster images such as JPEG or PNG aren’t scalable since they don’t have vectors or scaling information. ![]() They are widely popular and supported by both old and modern browsers. Raster images are bitmap graphics that use tiny pixels to create a grid that forms the Image. >setFormat('png')->convert()->save('ubuntu3.png') Ĭonvert -loop 0 -delay 25 ubuntu1.png ubuntu2.png ubuntu3.png ubuntu.This tool allows users to convert SVG to raster images. $svg3 = (new SVG)->init('phantomjs', 'ubuntu.svg') $svg2 = (new SVG)->init('phantomjs', 'ubuntu.svg') $svg = (new SVG)->init('phantomjs', 'debian.svg') Save file $svg-> save( 'file.png') //save file Image testsĪll images you can find in unit tests folder. $svg->getFormat() ĭisplay file $svg-> display() //display imageĭownload file $svg-> download() //download file Set output format $svg-> setFormat( 'pdf') //set output format to pdf //echo 'output format: '. Set size $svg-> setWidth( 500) //set output width to 500px $svg-> setHeight( 300) //set output height to 300px //echo 'output size: '. Set zoom $svg-> setZoom( 2.5) //enlarge original svg size up to 2.5x Open file $svg-> open( 'file.svg') //open file $svg-> save( 'outputfile.png') Other useful methods $svg-> setAttribute( 'path', 'fill', '#131C77') //change fill color to all paths $svg-> setFormat( 'png') $svg-> save( 'outputfile.png') Manipulate and convert SVG file in PHP init( 'phantomjs', 'inputfile.svg') Or if you want to use rsvg-convert $svg = ( new SVG)-> init( 'rsvg') init( 'phantomjs', 'inputfile.svg') Initializing method with phantomjs argument when you want use to PhantomJS engine $svg = ( new SVG)-> init( 'phantomjs') Psvg-convert svgfile outputfile Convert SVG file in PHP Psvg-convert inputfile.svg outputfile.png Usage Sudo apt-get install libcairo2-dev libspectre-dev librsvg2-dev \ libpoppler-glib-dev librsvg2-bin Examples Convert SVG to PNG format using PhantomJS CLI script Sudo cp src/js/psvg-convert.js /usr/local/bin/psvg-convert Install RSVG (only if you want to convert svg using librsvg) Sudo ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/ Use psvg-convert script globally chmod +x src/js/psvg-convert.js Next, create a symlink of PhantomJS binary file to systems bin directory: ![]() Sudo tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2 -C /usr/local/share/ You can download the latest stable version of the PhantomJS from their official website.Įxtract the downloaded archive file to desired system location: Next, you will need to download the PhantomJS. Sudo apt-get install build-essential chrpath libssl-dev libxft-dev libfreetype6-dev libfreetype6 libfontconfig1-dev libfontconfig1 -y You can install all of them with the following commands: Install PhantomJSīefore installing PhantomJS, you will need to install some required packages on your system. Package includes CLI (phantomjs script) to render and php adapter to manipulate and convert SVG format using phantomjs or rsvg-convert (librsvg). Various helpers to convert SVG files to other formats, especially PNG and PDF.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |