I had the same problem with a JPEG or PNG image (with a transparent background).
I found out that the hue class is not working properly, so I changed it a bit. You can find the stream in Google Groups: https://groups.google.com/forum/#!msg/fabricjs/DPN0WuRtc-o/ZGgIQK5F9xAJ
Here is my workaround class (which works using the full hex value, but you can easily adapt it to your needs):
fabric.Image.filters.Tint = fabric.util.createClass({ type: 'Tint', /** * Constructor * @memberOf fabric.Image.filters.Tint.prototype * @param {Object} [options] Options object */ //That Different : HexColor initialize: function(HexColor) { this.color = HexColor; }, /** * Applies filter to canvas element * @param {Object} canvasEl Canvas element to apply filter to */ applyTo: function(canvasEl) { var context = canvasEl.getContext('2d'), imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height), data = imageData.data; //That different : computation of values var rUser = ((this.color).toString ()).substr(0,2); var gUser = ((this.color).toString ()).substr(2,2); var bUser = ((this.color).toString ()).substr(4,2); for (var i = 0, len = data.length; i < len; i += 4) { r = data[i]; g = data[i + 1]; b = data[i + 2]; data[i] = parseInt ((r * parseInt (rUser, 16))/255); data[i + 1] = parseInt ((g * parseInt (gUser, 16))/255); data[i + 2] = parseInt ((b * parseInt (bUser, 16))/255); } context.putImageData(imageData, 0, 0); }, /** * Returns json representation of filter * @return {Object} json representation of filter */ toJSON: function() { return { type: this.type, color: this.color }; }
}) `
I use it this way tho:
//$oCanvas is my fabric Canvas object //data.color could be 'ff0000' but not 'f00' not anything else like fabric.Color $img.filters[0] = new fabric.Image.filters.Tint(data.color); $img.applyFilters($oCanvas.renderAll.bind($oCanvas));
Hope this helps someone.
L.
EDIT
Some changes have been made inside the hue filter class (Github: https://github.com/kangax/fabric.js/pull/862 ).
I tested it again, but I still had no luck, so I changed it a bit. You can find the source code + explanations in Google Groups ( https://groups.google.com/forum/#!topic/fabricjs/DPN0WuRtc-o )
EDIT No. 2
So, Kienz made a JSFiddle ( http://jsfiddle.net/Kienz/4wGzk/ ) that uses the hue filter class with error correction, and it got it working. I would recommend implementing it the way it did.