{"action":"created","issue":{"url":"https://api.github.com/repos/nodeca/mincer/issues/181","labels_url":"https://api.github.com/repos/nodeca/mincer/issues/181/labels{/name}","comments_url":"https://api.github.com/repos/nodeca/mincer/issues/181/comments","events_url":"https://api.github.com/repos/nodeca/mincer/issues/181/events","html_url":"https://github.com/nodeca/mincer/issues/181","id":56251492,"number":181,"title":"How to add an imgCompressor?","user":{"login":"Antiokus314","id":7415011,"avatar_url":"https://avatars.githubusercontent.com/u/7415011?v=3","gravatar_id":"","url":"https://api.github.com/users/Antiokus314","html_url":"https://github.com/Antiokus314","followers_url":"https://api.github.com/users/Antiokus314/followers","following_url":"https://api.github.com/users/Antiokus314/following{/other_user}","gists_url":"https://api.github.com/users/Antiokus314/gists{/gist_id}","starred_url":"https://api.github.com/users/Antiokus314/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Antiokus314/subscriptions","organizations_url":"https://api.github.com/users/Antiokus314/orgs","repos_url":"https://api.github.com/users/Antiokus314/repos","events_url":"https://api.github.com/users/Antiokus314/events{/privacy}","received_events_url":"https://api.github.com/users/Antiokus314/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nodeca/mincer/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-02-02T15:39:42Z","updated_at":"2015-02-04T06:18:49Z","closed_at":null,"body":"Adding a jsCompressor/cssCompressor was fairly straightforward - since they were already extending onto the Mincer/Environment objects. However, add a custom image compression class is definitely not the case. \r\n\r\n#### Here's what I did\r\n* Registered the mime type\r\n* Created a custom class for image minification\r\n* Followed the layout in compressing.js --- 124-152\r\n```\r\nMincer.registerMimeType('image/png', '.png')\r\n\r\nvar CustomImageCompressor = function CustomImageCompressor() {\r\n  Mincer.Template.apply(this, arguments);\r\n};\r\n\r\nCustomImageCompressor.prototype.evaluate = function() {\r\n  console.log('Custom image compressor');\r\n// My image compression stuff;\r\n};\r\n\r\nObject.defineProperty(module.exports, 'imgCompressor', {\r\n  get: function () {\r\n    return this.__imgCompressor__ || null;\r\n  },\r\n\r\n  set: function (compressor) {\r\n    var mime = 'image/png';\r\n\r\n    if (this.__imgCompressor__) {\r\n      this.unregisterBundleProcessor(mime, this.__imgCompressor__);\r\n    }\r\n\r\n    if (_.isFunction(compressor)) {\r\n      this.__imgCompressor__ = compressor;\r\n      this.registerBundleProcessor(mime, 'img_compressor', compressor);\r\n      return;\r\n    }\r\n\r\n    if (this.__compressors__.get(mime)[compressor]) {\r\n      this.__imgCompressor__ = this.__compressors__.get(mime)[compressor];\r\n      this.registerBundleProcessor(mime, this.__imgCompressor__);\r\n      return;\r\n    }\r\n\r\n    throw new Error('Unknown compressor: ' + compressor);\r\n  }\r\n});\r\n\r\nMincer.registerCompressor('image/png', 'myImgCompressor', CustomImageCompressor);\r\n```\r\n\r\nI then try to set it on my new environment object like so\r\n```\r\nvar environment = new Mincer.Environment();\r\nenvironment.imgCompressor = 'myImgCompressor'\r\n```\r\n\r\nHowever my ```console.log``` statement inside the ```evaluate``` method never gets called, so I know that it isn't working. Any guidance as to what I'm missing?"},"comment":{"url":"https://api.github.com/repos/nodeca/mincer/issues/comments/72796829","html_url":"https://github.com/nodeca/mincer/issues/181#issuecomment-72796829","issue_url":"https://api.github.com/repos/nodeca/mincer/issues/181","id":72796829,"user":{"login":"Antiokus314","id":7415011,"avatar_url":"https://avatars.githubusercontent.com/u/7415011?v=3","gravatar_id":"","url":"https://api.github.com/users/Antiokus314","html_url":"https://github.com/Antiokus314","followers_url":"https://api.github.com/users/Antiokus314/followers","following_url":"https://api.github.com/users/Antiokus314/following{/other_user}","gists_url":"https://api.github.com/users/Antiokus314/gists{/gist_id}","starred_url":"https://api.github.com/users/Antiokus314/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Antiokus314/subscriptions","organizations_url":"https://api.github.com/users/Antiokus314/orgs","repos_url":"https://api.github.com/users/Antiokus314/repos","events_url":"https://api.github.com/users/Antiokus314/events{/privacy}","received_events_url":"https://api.github.com/users/Antiokus314/received_events","type":"User","site_admin":false},"created_at":"2015-02-04T06:18:49Z","updated_at":"2015-02-04T06:18:49Z","body":"Does that actually work? I tried implementing it and I found that the images were being mangled by Mincer. I made sure it wasn't the image compression library, and just made it load only the files at compile time (without doing anything)\r\n\r\ne.g.\r\n```javascript\r\nvar environment = new Mincer.Environment();\r\nenvironment.appendPath(scripts_dir);\r\nenvironment.appendPath(styles_dir);\r\nenvironment.appendPath(images_dir);\r\n\r\nvar manifest = new Mincer.Manifest(environment, './public/assets');\r\nmanifest.compile(['**/*.(js|css|png)']);\r\n```\r\nThe js and css files get copied over without being modified, however that doesn't seem to be the case with the images.\r\n\r\nIs Mincer doing something to the image files during the compiling process that is making un-processable?"}}