gulp-raster icon indicating copy to clipboard operation
gulp-raster copied to clipboard

Final image has whitespace trimmed

Open thasmo opened this issue 10 years ago • 9 comments

It seems like rasterizing an SVG image trims all whitespace which results in a smaller (pixel) size compared to the original SVG file.

Any idea why this happens?

thasmo avatar Dec 09 '14 22:12 thasmo

Could you provide sample svg to reproduce this bug, please?

Otouto avatar Dec 10 '14 12:12 Otouto

@Otouto, SVG is here; PNG here.

thasmo avatar Dec 10 '14 22:12 thasmo

Yep I'm also having this issue, I'm using gulp-svg-sprites to generate a SVG that has 20px padding, but the piped output from gulp-raster is clipping off the top, bottom and left padding from the png. Not ideal!

stikoo avatar Dec 20 '14 16:12 stikoo

Getting the same issue, screenshot example attached. Left is PNG, right is the SVG. Transparent pixels appear to be trimmed off. trimmed-icon

daviddarnes avatar Jan 05 '15 12:01 daviddarnes

It would be nice to not have the padding removed.

amster avatar Apr 02 '15 22:04 amster

I'm having the same issue here and would love to get this feature as well.

Thanks.

ghost avatar Apr 07 '15 15:04 ghost

Unfortunately the same issue. Even if I add a background style, width and height to of the source files. Any suggestions or workarounds?!

bm2u avatar Sep 23 '15 10:09 bm2u

Got a workaround:

I'm using gulp-cheerio to manipulate the source SVG before rastering. Adding a rectangle after your path and set the fill-opacity to '0' resolves the cropping issue.

Example:

var gulp = require('gulp'),
    cheerio = require('gulp-cheerio'),
    raster = require('gulp-raster');
...
.pipe(cheerio({
    run: function ($) {
        $('path')
            .after('<rect fill="#ffffff" fill-opacity="0"/>');
        $('rect')
            .attr({
                height: size,
                width: size
            });
    }
...

bm2u avatar Sep 25 '15 06:09 bm2u

@bm2u nice work around! I think I was using cheerio at the time as well :)

daviddarnes avatar Sep 25 '15 08:09 daviddarnes