Php svg to jpeg

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

PHP helpers to manipulate SVG and convert SVG format to PNG or PDF

msztorc/svg-convert

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

svg-convert

Various helpers to convert SVG files to other formats, especially PNG and PDF. Package includes CLI (phantomjs script) to render and php adapter to manipulate and convert SVG format using phantomjs or rsvg-convert (librsvg).

Читайте также:  Вопросы собеседования php программиста

Before installing PhantomJS, you will need to install some required packages on your system. You can install all of them with the following commands:

sudo apt-get install build-essential chrpath libssl-dev libxft-dev libfreetype6-dev libfreetype6 libfontconfig1-dev libfontconfig1 -y

Next, you will need to download the PhantomJS. You can download the latest stable version of the PhantomJS from their official website.

Extract the downloaded archive file to desired system location:

sudo tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2 -C /usr/local/share/

Next, create a symlink of PhantomJS binary file to systems bin directory:

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 sudo cp src/js/psvg-convert.js /usr/local/bin/psvg-convert

Install RSVG (only if you want to convert svg using librsvg)

sudo apt-get install libcairo2-dev libspectre-dev librsvg2-dev \ libpoppler-glib-dev librsvg2-bin

Convert SVG to PNG format using PhantomJS CLI script

psvg-convert inputfile.svg outputfile.png

psvg-convert svgfile outputfile [—width=800 —height=600 —zoom=2.5 —format=png|pdf]

Initializing method with phantomjs argument when you want use to PhantomJS engine

$svg = (new SVG)->init('phantomjs');

or if you want to use rsvg-convert

 $svg = (new SVG)->init('phantomjs', 'inputfile.svg'); $svg->setFormat('png'); $svg->convert(); $svg->save('outputfile.png');

Manipulate and convert SVG file in PHP

 $svg = (new SVG)->init('phantomjs', 'inputfile.svg'); $svg->setAttribute('path', 'fill', '#131C77'); //change fill color to all paths $svg->setFormat('png'); $svg->convert(); $svg->save('outputfile.png');
$svg->setZoom(2.5); //enlarge original svg size up to 2.5x
$svg->setWidth(500); //set output width to 500px $svg->setHeight(300); //set output height to 300px //echo 'output size: ' . $svg->getWidth() . 'x' . $svg->getHeight();
$svg->setFormat('pdf'); //set output format to pdf //echo 'output format: ' . $svg->getFormat();
$svg->download(); //download file

All images you can find in unit tests folder.

 $svg = (new SVG)->init('phantomjs', 'debian.svg'); $svg->setAttribute('path', 'fill', '#131C77')->setFormat('png')->convert()->save('debian-blue.png'); $svg->setAttribute('path', 'fill', '#06A70D')->setFormat('png')->convert()->save('debian-green.png'); 

$svg1 = (new SVG)->init('phantomjs', 'ubuntu.svg')->setFormat('png')->convert()->save('ubuntu1.png'); $svg2 = (new SVG)->init('phantomjs', 'ubuntu.svg') ->setAttribute('use[1]', 'fill', '#f40') ->setAttribute('use[2]', 'fill', '#f80') ->setAttribute('use[3]', 'fill', '#d00') ->setAttribute('use[4]', 'fill', '#f40') ->setAttribute('use[5]', 'fill', '#f80') ->setAttribute('use[6]', 'fill', '#d00') ->setFormat('png')->convert()->save('ubuntu2.png'); $svg3 = (new SVG)->init('phantomjs', 'ubuntu.svg') ->setAttribute('use[1]', 'fill', '#f80') ->setAttribute('use[2]', 'fill', '#d00') ->setAttribute('use[3]', 'fill', '#f40') ->setAttribute('use[4]', 'fill', '#f80') ->setAttribute('use[5]', 'fill', '#d00') ->setAttribute('use[6]', 'fill', '#f40') ->setFormat('png')->convert()->save('ubuntu3.png'); 

Create gif using imagemagick

convert -loop 0 -delay 25 ubuntu1.png ubuntu2.png ubuntu3.png ubuntu.gif

Источник

Convert SVG to JPEG via PHP Cloud API

Transform SVG into JPEG using native PHP Cloud APIs without needing any image editor or 3rd-party libraries.

Aspose.Imaging.Cloud for PHP

Overview

Download from NuGet

Open NuGet package manager, search for and install.
You may also use the following command from the Package Manager Console.

How to Convert SVG to JPEG Using PHP Cloud API

Aspose.Imaging.Cloud for PHP API which is a feature-rich, powerful and easy to use image manipulation and conversion Cloud API for PHP platform. You can install its latest version from Packagist

composer.json fragment

  "require":   "aspose/aspose-imaging-cloud": ">=version of aspose-imaging-cloud API"  > > 

Steps to Convert SVG to JPEG via PHP Cloud API

Developers can easily load & convert SVG files to JPEG in just a few lines of code.

  • Load SVG file as stream
  • Create & set the instance of CreateConvertedImageRequest
  • Call the CreateConvertedImage method
  • Get converted image from response stream

System Requirements

Aspose.Imaging Cloud for PHP is supported on all major operating systems. Just make sure that you have the following prerequisites.

Convert SVG to JPEG — Cloud

About Aspose.Imaging Cloud API for PHP

Aspose.Imaging Cloud API is an image processing solution to process images (photos) within your cloud or web applications. It offers: cross-platform Image processing, including but not limited to conversions between various image formats (including uniform multi-page or multi-frame image processing), transformations (resize, crop, flip&rotate, grayscale, adjust), advanced image manipulation features (filtering, deskewing), AI features (i.e. object detection and reverse image search). It’s a Cloud API and does not depend on any software for image operations. One can easily add high-performance image conversion features with Cloud APIs within projects. Flexible integrations options including SDKs for various languages (Python, Ruby, .NET, Java, NodeJS, PHP) and the use of the REST API allow to make the integration easy.

Convert SVGs via Online App

Convert SVG to JPEG documents by visiting our Live Demos website. The live demo has the following benefits

SVG What is SVG File Format

SVG files are Scalable Vector Graphics Files that use XML based text format for describing the appearance of image. The word Scalable refers to the fact that the SVG can be scaled to different sizes without losing any quality. Text based description of such files make them independent of resolution. It is one of the mostly used format for building website and print graphics in order to achieve scalability. The format can only be used for two-dimensional graphics though. SVG files can be viewed/opened in almost all modern browsers including Chrome, Internet Explorer, Firefox, and Safari.

JPEG What is JPEG File Format

A JPEG is a type of image format that is saved using the method of lossy compression. The output image, as result of compression, is a trade-off between storage size and image quality. Users can adjust the compression level to achieve the desired quality level while at the same time reduce the storage size. Image quality is negligibly affected if 10:1 compression is applied to the image. The higher the compression value, the higher the degradation in image quality.

Other Supported Conversions

Using PHP Cloud API, one can easily convert different formats including.

Источник

README

This package relies on the sharp js package being available on your system. In most cases you can accomplish this by issue this command in your project.

Usage

use Choowx\RasterizeSvg\Svg; $svgString = '; $jpegBinaryString = Svg::make($svgString)->toJpeg(); $jpegBinaryString = Svg::make($svgString)->toJpg(); // Alias of toJpeg() $pngBinaryString = Svg::make($svgString)->toPng(); $webpBinaryString = Svg::make($svgString)->toWebp();

If you want to straight away save the rasterized image on disk:

use Choowx\RasterizeSvg\Svg; $svgString = '; Svg::make($svgString)->saveAsJpeg('path/to/rasterized.jpeg'); Svg::make($svgString)->saveAsJpg('path/to/rasterized.jpg'); // Alias of saveAsJpeg() Svg::make($svgString)->saveAsPng('path/to/rasterized.png'); Svg::make($svgString)->saveAsWebp('path/to/rasterized.webp');

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Источник

Оцените статью