I have a small webapp written in JavaScript for WeChat platform, where users can create some images and submit it to server.
Image creation is done using Canvas2D.
Submitting image to server I do using image data string that I receive from canvas.toDataURL(type,quality) and then server PHP script creates binary JPG file on server side once received from the webapp.
All works great on all phones I had opportunity to try (Samsung S3/4/5, Xiaomi, Huawei Honor, Lenovo, Nexus 4/5, iPhone 4S/5/5S/6/6S, iPads...), no issues. Except on client's Samsung Note 2.
Their device runs Android 4.3 and up-to-date WeChat (6.2.6) just like on my Android phones. However, when they submit picture, filesize is 6-7 times larger.
I've checked and actually received file is PNG, and not JPG.
Codes that I use to get image data string from Canvas2D image is:
var jpgData = this.finalPicCanvas.toDataURL("image/jpeg",0.5);
I have set that PHP script that receives this data string, to write down log, what was in the header, received string size etc, and I can clearly see that only when client submits image, received header is "image/png" regardless that in javascript code is set to "image/jpeg".
Here is the log showing png header and large data size: http://snag.gy/ma39y.jpg
Here is the log showing jpg header and normal data size:http://snag.gy/enPvZ.jpg
I am puzzled, what did I do wrong? I have checked specification and toDataURL should be supported since Android 3.4
I've found this specification from 2011 that browsers must support PNG but they are not required to support any other formats and that if provided type is not recognized, that it will return PNG: http://www.w3.org/TR/2011/WD-html5-20110405/the-canvas-element.html#dom-canvas-todataurl
However, considering this is 2015, age of WebGL and mobile devices, I find it hard to believe that there's nothing I can do.
Does anyone has a solution? Highly appreciated!!!