<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Mathias Reker</title>
    <description>The latest articles on Forem by Mathias Reker (@mreker).</description>
    <link>https://forem.com/mreker</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3773679%2F36fc0188-4e8f-46d2-94a9-f8821fcba74b.png</url>
      <title>Forem: Mathias Reker</title>
      <link>https://forem.com/mreker</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mreker"/>
    <language>en</language>
    <item>
      <title>SVG files are everywhere — icons, logos, illustrations, UI graphics...</title>
      <dc:creator>Mathias Reker</dc:creator>
      <pubDate>Sun, 15 Feb 2026 08:02:14 +0000</pubDate>
      <link>https://forem.com/mreker/svg-files-are-everywhere-icons-logos-illustrations-ui-graphics-4fg2</link>
      <guid>https://forem.com/mreker/svg-files-are-everywhere-icons-logos-illustrations-ui-graphics-4fg2</guid>
      <description>&lt;p&gt;SVG files are everywhere - icons, logos, illustrations, UI graphics. They're lightweight, scalable, and web-friendly. But SVGs exported from design tools often contain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unnecessary metadata&lt;/li&gt;
&lt;li&gt;Redundant attributes&lt;/li&gt;
&lt;li&gt;Editor-specific footprints&lt;/li&gt;
&lt;li&gt;Excess whitespace&lt;/li&gt;
&lt;li&gt;Potentially unsafe elements&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you're working in PHP and want a robust, configurable, and security-aware SVG optimizer, there's now a purpose-built solution:&lt;/p&gt;

&lt;p&gt;👉 &lt;code&gt;https://github.com/MathiasReker/php-svg-optimizer&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;php-svg-optimizer is a lightweight PHP library designed to optimize, minify, and sanitize SVG files while staying compliant with SVG 2.0 specifications.&lt;/p&gt;

&lt;h1&gt;
  
  
  The result?
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Smaller files&lt;/li&gt;
&lt;li&gt;Cleaner markup&lt;/li&gt;
&lt;li&gt;Standards-compliant SVG&lt;/li&gt;
&lt;li&gt;Safer embedding&lt;/li&gt;
&lt;li&gt;Visually identical output&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Why SVG Optimization Matters
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Performance&lt;br&gt;
Smaller SVG files mean:&lt;br&gt;
Faster page loads&lt;br&gt;
Better Lighthouse scores&lt;br&gt;
Reduced bandwidth usage&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Security&lt;br&gt;
SVG is XML-based - and XML can contain:&lt;br&gt;
&lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags&lt;br&gt;
Event handlers (onclick, etc.)&lt;br&gt;
External references&lt;br&gt;
Embedded malicious payloads&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you accept SVG uploads from users, sanitization isn't optional - it's critical.&lt;/p&gt;




&lt;p&gt;Installation&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer require mathiasreker/php-svg-optimizer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two Ways to Use It:&lt;/p&gt;

&lt;p&gt;1️⃣ Command Line (CLI)&lt;br&gt;
Perfect for:&lt;br&gt;
CI pipelines&lt;br&gt;
Build steps&lt;br&gt;
Batch processing&lt;br&gt;
Pre-commit hooks&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vendor/bin/svg-optimizer --with-all-rules process /path/to/svgs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;2️⃣ As a PHP Package&lt;br&gt;
This is where the library really shines - fully configurable, fluent, and exception-safe.&lt;br&gt;
Basic Example (Default Rules)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

declare(strict_types=1);

require_once __DIR__ . '/vendor/autoload.php';

use MathiasReker\PhpSvgOptimizer\Service\Facade\SvgOptimizerFacade;

try {
    $svgOptimizer = SvgOptimizerFacade::fromFile('path/to/source.svg')
        -&amp;gt;withAllRules()
        -&amp;gt;optimize()
        -&amp;gt;saveToFile('path/to/output.svg');

    $metaData = $svgOptimizer-&amp;gt;getMetaData();

    echo sprintf('Optimized size: %d bytes%s', $metaData-&amp;gt;getOptimizedSize(), \PHP_EOL);
    echo sprintf('Original size: %d bytes%s', $metaData-&amp;gt;getOriginalSize(), \PHP_EOL);
    echo sprintf('Size reduction: %d bytes%s', $metaData-&amp;gt;getSavedBytes(), \PHP_EOL);
    echo sprintf('Reduction percentage: %s %%%s', $metaData-&amp;gt;getSavedPercentage(), \PHP_EOL);
    echo sprintf('Processing time: %s seconds%s', $metaData-&amp;gt;getOptimizationTime(), \PHP_EOL);
} catch (\Exception $exception) {
    echo $exception-&amp;gt;getMessage();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;What Makes It Powerful?&lt;br&gt;
The library implements the Strategy Pattern, where each optimization rule is encapsulated in its own class.&lt;br&gt;
You can enable rules individually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-&amp;gt;withRules(
    convertColorsToHex: true,
    convertCssClassesToAttributes: true,
    convertEmptyTagsToSelfClosing: true,
    convertInlineStylesToAttributes: true,
    fixAttributeNames: false,
    flattenGroups: true,
    minifySvgCoordinates: true,
    minifyTransformations: true,
    removeAriaAndRole: true,
    removeComments: true,
    removeDataAttributes: false,
    removeDefaultAttributes: true,
    removeDeprecatedAttributes: true,
    removeDoctype: true,
    removeDuplicateElements: true,
    removeEmptyAttributes: true,
    removeEmptyGroups: true,
    removeEmptyTextElements: true,
    removeEnableBackgroundAttribute: false,
    removeInkscapeFootprints: true,
    removeInvisibleCharacters: true,
    removeMetadata: true,
    removeNonStandardAttributes: false,
    removeNonStandardTags: false,
    removeTitleAndDesc: true,
    removeUnnecessaryWhitespace: true,
    removeUnsafeElements: false,
    removeUnusedMasks: true,
    removeUnusedNamespaces: true,
    removeWidthHeightAttributes: false,
    sortAttributes: true,
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Secure SVG Upload Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SvgOptimizerFacade::fromFile('uploaded.svg')
    -&amp;gt;withRules(sp
        removeUnsafeElements: true,
        removeNonStandardTags: true,
        removeNonStandardAttributes: true
    )
    -&amp;gt;allowRisky()
    -&amp;gt;optimize()
    -&amp;gt;saveToFile('sanitized.svg');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This significantly reduces the risk of XSS when embedding user-uploaded SVGs.&lt;/p&gt;




&lt;p&gt;Developer Experience&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The project emphasizes:&lt;/li&gt;
&lt;li&gt;PHPStan Level 9&lt;/li&gt;
&lt;li&gt;100% type coverage&lt;/li&gt;
&lt;li&gt;High test coverage&lt;/li&gt;
&lt;li&gt;Strategy-based architecture&lt;/li&gt;
&lt;li&gt;Deterministic output&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you're working with SVGs in PHP, this tool deserves a place in your workflow.&lt;/p&gt;




&lt;p&gt;⭐ If you find it useful, consider giving it a star on GitHub.&lt;/p&gt;

</description>
      <category>php</category>
      <category>svg</category>
      <category>performance</category>
      <category>security</category>
    </item>
  </channel>
</rss>
