dbushell / grunt-svg2png

Grunt plugin to rasterize SVG to PNG images using PhantomJS
MIT License
76 stars 37 forks source link

Dynamic mapping / rasterization bug #16

Open ismay opened 10 years ago

ismay commented 10 years ago

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 commented 10 years ago

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!

dbushell commented 10 years ago

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!

ismay commented 10 years ago

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.

msguerra74 commented 10 years ago

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!

coreyworrell commented 9 years ago

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