Download the PHP package meyfa/php-svg without Composer

On this page you can find all versions of the php package meyfa/php-svg. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-svg

PHP-SVG

The zero-dependency vector graphics library for PHP applications

CI Maintainability Test Coverage Packagist PHP Version Packagist Downloads

Features

PHP-SVG can help with the following set of tasks:

Please note that PHP-SVG is still in its alpha stage and may not be suitable for complex applications, yet. Contributions are very welcome. Find out how to contribute.

Installation

Requirements

PHP-SVG is free of dependencies. All it needs is a PHP installation satisfying the following requirements:

These extensions are almost always available on typical PHP installations. Still, you might want to make sure that your hosting provider actually has them. If SimpleXML or GD are missing, PHP-SVG can still perform all tasks except those that require the missing extension. For example, programmatically generating SVG images and outputting them as XML will always work, even without any extension.

Composer (recommended)

This package is available on Packagist and can be installed with Composer:

This adds a dependency to your composer.json file. If you haven't already, setup autoloading for Composer dependencies by adding the following require statement at the top of your PHP scripts:

You may need to adjust the path if your script is located in another folder.

Manual installation

Download the latest release or the current development version of this repository, and extract the source code somewhere in your project. Then you can use our own autoloader to make available the SVG namespace:

The rest works exactly the same as with Composer, just without the benefits of a package manager.

Getting started

This section contains a few simple examples to get you started with PHP-SVG.

Creating SVGs programmatically

The following code generates an SVG containing a blue square. It then sets the Content-Type header and sends the SVG as text to the client:

Converting SVGs to strings

The above example uses echo, which implicitly converts the SVG to a string containing its XML representation. This conversion can also be made explicitly:

Loading SVGs from strings

In addition to generating images programmatically from scratch, they can be parsed from strings or loaded from files. The following code parses an SVG string, mutates part of the image, and echoes the result to the client:

Loading SVGs from files

For loading from a file instead of a string, call SVG::fromFile($file). That function supports paths on the local file system, as well as remote URLs. For example:

Rasterizing

:warning: This feature in particular is very much work-in-progress. Many things will look wrong and rendering large images may be very slow.

The toRasterImage($width, $height [, $background]) method is used to render an SVG to a raster image. The result is a GD image resource. GD then provides methods for encoding this resource to a number of formats:

The raster image will default to preserving any transparency present in the SVG. For cases where an opaque image is desired instead, it is possible to specify a background color. This may be mandatory when outputting to some formats, such as JPEG, that cannot encode alpha channel information. For example:

Text rendering (loading fonts)

PHP-SVG implements support for TrueType fonts (.ttf files) using a handcrafted TTF parser. Since PHP doesn't come with any built-in font files, you will need to provide your own. The following example shows how to load a set of font files. PHP-SVG will try to pick the best matching font for a given text element, based on algorithms from the CSS spec.

Note that PHP often behaves unexpectedly when using relative paths, especially with fonts. Hence, it is recommended to use absolute paths, or use the __DIR__ constant to prepend the directory of the current script.

Document model

This section explains a bit more about the object structure and how to query or mutate parts of documents.

SVG root node

An instance of the SVG class represents the image abstractly. It does not store DOM information itself. That is the responsibility of the document root node, which is the object corresponding to the <svg> XML tag. For example:

Child nodes

Child nodes of any element can be obtained as follows:

The root node has an additional function for obtaining a unique element by its id attribute:

Child nodes can be added, removed and replaced:

Attributes

Every attribute is accessible via $element->getAttribute($name). Some often-used attributes have additional shortcut methods, but they are only available on the classes for which they are valid, so make sure the node you are accessing is of the correct type to prevent runtime errors. Some examples:

Styles

Some presentation attributes are considered style properties by the SVG spec. These will be treated specially by PHP-SVG and made available via getStyle and setStyle instead of getAttribute and setAttribute. Consider the following node:

Debugging

If you aren't getting any output but only a blank page, try temporarily enabling PHP's error reporting to find the cause of the problem.

Make sure you disable this again when you're done, as it may leak sensitive information about your server setup. Additionally, ensure you're not setting the Content-Type header to an image format in this mode, as your browser will try to render the error message as an image, which won't work.

Alternatively, you may attempt to find your server's error log file. Its location depends on how you're running PHP.

Contributing

This project is available to the community for free, and there is still a lot of work to do. Every bit of help is welcome! You can contribute in the following ways:

Please read:

By contributing material or code to PHP-SVG via a pull request or commit, you confirm that you own the necessary rights to that material or code, and agree to make available that material or code under the terms of the MIT license.


All versions of php-svg with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package meyfa/php-svg contains the following files

Loading the files please wait ....