Download the PHP package mathiasreker/php-svg-optimizer without Composer

On this page you can find all versions of the php package mathiasreker/php-svg-optimizer. 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-optimizer

PHP SVG Optimizer

Packagist Version Packagist Downloads CI status Contributors Forks Stargazers Issues MIT License

php-svg-optimizer is a PHP library designed to optimize SVG files by applying various transformations and cleanup operations. The library ensures that the optimized SVG files are compliant with SVG 2.0 specifications.

The tool strives to optimize as much as possible without losing any data that could distort the image's quality, ensuring the resulting SVG remains visually identical to the original while being more efficient in terms of size and performance.

Versions & Dependencies

Version PHP Documentation
^5.2 ^8.3 current

Requirements

Installation

To install the library, run:

Using the Library

You can use this library either as a command-line tool (CLI) or as a standalone package.


CLI tool

Usage

Examples:

Config file example:

Package

To ensure robustness when using the library, it's crucial to handle exceptions, as invalid or malformed SVG files could lead to runtime errors. Catching these exceptions will allow you to manage potential issues gracefully and prevent your application from crashing.

Example specifying rules

Example parsing from a file and saving to a file using default rules

Example parsing from a file and returning the content using default rules

Example parsing from a string and returning the content using default rules

Documentation

Static factory method to create SvgOptimizerService from a file path.

Static factory method to create SvgOptimizerService from a string.

withRules Method

Configure which SVG optimization rules to apply. The method accepts boolean parameters that determine whether specific rules should be enabled or disabled.

Parameters:

Removes <title> and <desc> tags from the SVG:

Removes all comments from the SVG:

Sorts attributes within each element:

Removes default attribute values that match common defaults:

Removes deprecated attributes from the SVG:

Removes <metadata> tags from the SVG:

Removes invisible characters from the SVG:

Flattens nested <g> elements, moving their child elements up to the parent node:

Converts rgb() color values to hexadecimal format:

Minifies coordinate values by removing unnecessary precision:

Minifies transformation attributes by removing redundant values:

Removes the SVG doctype declaration:

Removes the enable-background attribute from the SVG:

Removes empty attributes from the SVG:

Converts empty tags to self-closing tags:

Cleans up unnecessary whitespace in the SVG:

All options are set to true by default. You can configure them individually by passing the desired values to it:

optimize Method

Finalizes the optimization process and generates the optimized SVG file.

saveToFile Method

Saves the optimized SVG file to the specified path.

getContent Method

Returns the optimized SVG content.

getOptimizedSize Method

Returns the size of the optimized SVG file.

getOriginalSize Method

Returns the size of the original SVG file.

getSavedBytes Method

Returns the number of bytes saved by the optimization process.

getSavedPercentage Method

Returns the percentage of bytes saved by the optimization process.

Roadmap

For a complete list of proposed features and known issues, see the open issues.

Contributing

We welcome all contributions! If you have ideas for improvements, feel free to fork the repository and submit a pull request. You can also open an issue. If you find this project helpful, don’t forget to give it a star!

Library Structure and Contribution Guide

The library implements the Strategy Pattern, where strategies are encapsulated as "rules" located in the /src/Services/Rules directory.

Adding a New Rule

1. Create the Rule

Create a new final class in the /src/Services/Rules directory and implement the SvgOptimizerRuleInterface. This interface will define the logic for your rule.

2. Write Tests

Write comprehensive unit tests for your rule in the /tests/Unit/Services/Rules directory. Ensure the tests cover various scenarios to verify the correct behavior and edge cases for your rule.

3. Integrate the Rule

4. Update Documentation

Document the functionality and purpose of your rule in the README.md to ensure users understand its behavior and usage.

Docker

To use the project with Docker, you can start the container using:

Then, access the container:

Tools

Run PHPStan:

Run tests:

Format code:

License

This project is licensed under the MIT License. See the LICENSE file for more information.

Disclaimer

Although the tool has been thoroughly tested and is built in a way that avoids risky changes, its use is at your own risk. We cannot guarantee that it will be fully compatible with all SVG files or workflows. It is highly recommended to test the tool with sample SVG files and ensure compatibility with your specific use case before using it in a production environment.


All versions of php-svg-optimizer with dependencies

PHP Build Version
Package Version
Requires php Version >=8.3
ext-dom Version *
ext-libxml Version *
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 mathiasreker/php-svg-optimizer contains the following files

Loading the files please wait ....