Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gulp.spritesmith can't work with images created dynamically #53

Closed
Finesse opened this issue Jul 14, 2015 · 6 comments
Closed

Gulp.spritesmith can't work with images created dynamically #53

Finesse opened this issue Jul 14, 2015 · 6 comments

Comments

@Finesse
Copy link

Finesse commented Jul 14, 2015

Gulp.spritesmith should open input images from stream but it tries to open them from disk. For example, this:

var spriteData = gulp.src('.src/sprites/somePicture.svg')
    .pipe(svg2png())  // Converts svg image to png and passes to next plugin without saving on disk
    .pipe(spritesmith({
        imgName: 'sprite.png',
        cssName: 'sprite.css'
    }));

Causes error: Error: ENOENT, open './src/sprites/somePicture.png'.

@Finesse Finesse changed the title gulp.spritesmith can't work with images created dynamically Gulp.spritesmith can't work with images created dynamically Jul 14, 2015
@twolfson
Copy link
Owner

This is caused by the underlying architecture of spritesmith. Most engines wouldn't support input images streaming in (e.g. phantomjssmith loads images from disk as if we are in a browser, gmsmith has no way to differentiate when an image starts/stops via stdin).

That being said, the current error message is definitely cryptic and we should error out when we see a stream instead. Additionally, it would be nice to support streaming on those select engines that could (e.g. pixelsmith, canvassmith via data URIs maybe).

For your case, I suggest using a workaround for now:

// Define a task to convert SVGs to PNGs
gulp.task('convert-svg2png', function () {
  return gulp.src('.src/sprites/somePicture.svg')
    .pipe(gulp.dest('tmp/svg2png/'));
});

// Define our sprite task which is dependant on SVGs being converted to PNGs
gulp.task('sprite', ['convert-svg2png'], function () {
    var spriteData = gulp.src('tmp/svg2png/*.png')
        .pipe(spritesmith({
            imgName: 'sprite.png',
            cssName: 'sprite.css'
        }));
});

@Finesse
Copy link
Author

Finesse commented Jul 15, 2015

Thank you. I will do it this ways. It is not cool, but there is no choice.

@webcaetano
Copy link

I had the same problem.

@twolfson
Copy link
Owner

We have finally resolved this issue. In 5.0.0, we have added passing through Vinyl objects to our engines. As with gulp plugins, not all engines will support buffer/streams but some will (e.g. pixelsmith, canvassmith).

For upgrading instructions, please see our "Breaking changes" notes in the README. Thank you for reporting the initial issue =)

https://github.com/twolfson/gulp.spritesmith/tree/5.0.0#breaking-changes-in-500

@Finesse
Copy link
Author

Finesse commented Nov 18, 2015

Thank you!

@webcaetano
Copy link

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants