grunt-svg2png icon indicating copy to clipboard operation
grunt-svg2png copied to clipboard

Dynamic mapping / rasterization bug

Open ismay opened this issue 10 years ago • 5 comments

I'm using svg2png to render fallback png's and am encountering several bugs: when I run grunt svg2png with this config:

  build: {
    files: [{
      cwd: 'src/assets/ico',
      src: ['*.svg'],
      dest: 'build',
      ext: '.png'
    }]
  }

it hangs at 0% when rasterizing.

Adding expand

When I add expand:true the rasterization works, but folder structure it outputs is wrong. With src/assets/ico/test.svg the result is build/test.png/src/assets/ico/test.png. So it outputs the filename as a folder first and then messes up the folder structure (I believe it should be build/assets/ico/test.png). When I fiddle around with the cwd and src it keeps outputting the filename as a folder.

Removing ext

When I remove ext:'png' the folder structure becomes: build/test.svg/src/assets/ico/test.png.

Summary

  1. Doesn't work without expand:true
  2. Weird dynamic mapping behaviour

Any idea what's going wrong? To me it seems like there's something wrong with svg2png's implementation of grunt's dynamic mapping syntax, since similar syntax seems to work just fine with other plugins (copy for example).

ismay avatar Jun 25 '14 14:06 ismay

After some fiddling, the only syntax that seems to work for me is:

  build: {
    files: [{
      cwd: 'src/',
      src: ['assets/ico/**/*.svg'],
      dest: 'build/',
      expand: false
    }]
  }

So I still don't know what exactly was going wrong, but hope this is of help!

ismay avatar Jun 25 '14 15:06 ismay

Thanks @ismay, I'm glad you got it working :)

Recent changes had broke the old config options and I'm a bit behind on my Grunt files knowledge to understand exactly how it should work. I believe it's now correct though!

dbushell avatar Jul 07 '14 14:07 dbushell

I'm glad you got it working :)

Me too :)! I think I made a couple of mistakes in the config at first, but the final config should have worked with expand:true instead of expand:false (if I'm not misinterpreting Grunt's documentation: http://gruntjs.com/configuring-tasks#files).

I believe it's now correct though!

Is it this commit that should have fixed the dynamic mapping: 72976354a8590212e1ebb2802932adf80ec938d3? Because I can take a look and see if everything's working as expected now, if you'd like.

ismay avatar Jul 07 '14 14:07 ismay

Something happened between the last version and this one. I had been using the following config, which worked just fine:

svg2png: {
  svg: {
    files: [{
      src: '<%= source %>/_assets/images/**/*.svg',
      dest: '<%= source %>/assets/img'
    }]
  }
},

but now, I've had to modify it to this to make it work:

svg2png: {
  svg: {
    files: [{
      expand: false,
      cwd: '<%= source %>/_assets/images/',
      src: ['**/*.svg'],
      dest: '<%= source %>/assets/img'
    }]
  }
},

I am happy that I can still make it work, but it doesn't seem to follow the same structure as some of my other grunt tasks, and since it worked fine previously, something doesn't feel right here. Are there any plans to look into this, or do I change the config to what's working and move on? Thanks!

msguerra74 avatar Jul 12 '14 05:07 msguerra74

This doesn't seem to work anymore. If I do try this, the rasterization process just hangs up at 0, and nothing happens.

coreyworrell avatar Nov 26 '14 01:11 coreyworrell