1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-28 09:22:00 +03:00

plugins/removeRasterImages: remove raster images references in <image> (disabled by default) (close #98)

This commit is contained in:
deepsweet
2013-02-13 17:22:15 +02:00
parent 0ee129b0a2
commit 7ddc8ebbc0
6 changed files with 51 additions and 0 deletions

View File

@ -32,6 +32,10 @@ plugins:
active: true
type: perItem
- name: removeRasterImages
active: false
type: perItem
- name: cleanupNumericValues
active: true
type: perItem

View File

@ -0,0 +1,23 @@
'use strict';
/**
* Remove raster images references in <image>.
*
* @see https://bugs.webkit.org/show_bug.cgi?id=63548
*
* @param {Object} item current iteration item
* @return {Boolean} if false, item will be filtered out
*
* @author Kir Belevich
*/
exports.removeRasterImages = function(item) {
if (
item.isElem('image') &&
item.hasAttr('xlink:href') &&
/(\.|image\/)(jpg|png)/.test(item.attr('xlink:href').value)
) {
return false;
}
};

View File

@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g>
<image xlink:href="raster.jpg" width="100" height="100"/>
<image xlink:href="raster.png" width="100" height="100"/>
<image xlink:href="raster.svg" width="100" height="100"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 306 B

View File

@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g>
<image xlink:href="raster.svg" width="100" height="100"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 174 B

View File

@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g>
<image xlink:href="data:image/jpg;base64,..." width="100" height="100"/>
<image xlink:href="data:image/png;base64,..." width="100" height="100"/>
<image xlink:href="data:image/svg+xml;base64,..." width="100" height="100"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 355 B

View File

@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g>
<image xlink:href="data:image/svg+xml;base64,..." width="100" height="100"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 193 B