How to detect handling of image rotation by the browser engine version - cross-browser

I need to properly display an image depending on it exif image orientation tag.
I adjusted the rotation and flipping of the image for each case in the 8 possible image orientation options (described here)
I tested on the images in here
In Chrome (version 81.0) on Ubuntu 18.04, all image options display properly.
On MacOS and iOS I get different behaviors. Sometimes the images are not displayed properly
I read here that the behavior may change depending on the version of the webkit browser engine.
I want to adjust the code to each use case:
browser (e.g. Chrome, Firefox, Safari)
engine version (e.g. webkit version < 13.4, webkit version >= 13.4, etc...)
I read here and here that detecting the user agent is usually a bad idea, and that it is better to detect the existence of the feature
In my case, the feature exists in the different versions but the behavior of the agent is different between versions? (I think)
What would be the best way to detect the handling of image orientation (handling of exif imageOrientation tag)
Thanks,
Avner

That is cased because the default value of image-orientation has been changed in the recent versions of browsers.
From Chrome 81, the default value is from-image. https://chromestatus.com/feature/6313474512650240
In iOS, I observed that the value is from-image from iOS 13.4.
And I use the following code to detect the default value.
const getImageOrientation = (): string => {
const img = document.createElement('img');
img.style.display = 'none';
document.body.appendChild(img);
const imageOrientation = window.getComputedStyle(img).imageOrientation;
document.body.removeChild(img);
return imageOrientation;
};
if (getImageOrientation() !== 'from-image') {
// rotate image
}

Related

Why is my image rotated 45 degrees to the right on Safari, but not on other browsers? [duplicate]

I have an angular 2 application in production environment that allows you to choose a profile picture. Recently, performing tests with safari mobile, specifically for IOS 13.3.1 version(older) and IOS 13.4.1(new) version. I noticed that the image is shown rotated depending of safari browser version used (I built a stackblitz for this that you can review):
IOS 13.3.1 version(older)
IOS 13.4.1(new)
When I take images from an iPhone's in portrait mode and upload the image to my app it is shown rotated only for IOS 13.3.1 version(older). However, I examined the EXIF ​​meta-information images from each of my devices and found that both images have the same value in the orientation property:
IOS 13.3.1 version(older)
IOS 13.4.1(new)
My question is. Why does the image display change depending on the IOS version, knowing that in both cases the orientation EXIF is the same value (6)?
This is a subject that worries me since I had already solved this problem by rotating the image depending of EXIF orientation value for its correct display (e.g. exif.js have been created to handle this situation by detecting the exif orientation flag), but this problem now appears again with the new version of IOS. What would be an example of code that I can use to make it sustainable over time? Is there not a consensus among the browsers to manage the orientation of the images?
What is the explanation for this illogical behavior?
Thank you so much!
We also stumbled upon this when our mobile suddenly behaved differently and finally find the root cause of this.
Both WebKit (iOS) and Android (Chrome) have just recently changed the default behavior of the image-orientation CSS propterty. While it was none before, it is now from-image. This means: Before, they ignored the EXIF data of an image by default, while they are now using it to auto-correct the image. Which break our own auto-correction based on the exifreader library.
Here are some relevant links:
https://www.fxsitecompat.dev/en-CA/docs/2020/jpeg-images-are-now-rotated-by-default-according-to-exif-data/
https://bugs.webkit.org/show_bug.cgi?id=89052
Funny enough, also the Slack team seems to have run into this:
https://bugzilla.mozilla.org/show_bug.cgi?id=1634180
Fortunately, the author of the exifreader library (who just some weeks later ran into the same problems) also guided me to a way to detect the behavior. You can find his answer here:
https://github.com/mattiasw/ExifReader/issues/99#issuecomment-640217716
I also noticed that Modernizr has a test for this, so I am actually using a custom modernizr build now to detect the browser behavior.
The webkit browser is rotating the images before you upload them based on the EXIF data then it gets applied again by your app. We were able to confirm this on new (81) version of Chrome and Mobile Safari on 13.4. then the app is rotating them further and it gets twisted.

HTML5 Canvas image discoloration

I've noticed HTML5 Canvas adds slight discoloration on certain browsers when using drawImage. I know it happens on Google Chrome and Mozilla Firefox. Internet Explorer and Chrome Android seems to work fine. What is causing this? My context's globalAlpha is 1.0. The discoloration is usually 1-5 RGB values off. Note that there are no problems when using Canvas' fillRect, etc.
Upon further inspection, looks like this is more a problem from the browser combined with Photoshop exported images, and is irrelevant with the Canvas itself.
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var img = new Image();
img.src = "http://i.imgur.com/NTRjnRb.png";
img.onload = function(){
ctx.fillStyle = "#FFF";
ctx.fillRect(0, 0, 450, 800);
ctx.drawImage(img, 0, 0);
}
</script>
This is because of color management and is not related to canvas but to the image loading itself. When an image is loaded into memory the browser will apply monitor ICC as well as embedded ICC if any, to the color values. When you next draw the image to canvas the color values of the image is already set in stone.
Chrome and FF support ICC profiles directly and will apply using both image ICC (if any) and monitor ICC profile.
Internet Explorer v9-11 supports ICC through the Windows Color system.
In addition to ICC there is gamma correction which also may affect the actual color values in the out end. If that wasn't enough then there are different versions of ICC profiles, ie v4 does not have quite the support it should have by now.
ICC profile version test results:
ICC support: v2 v4
Firefox 34 X -
Chrome 40 / Opera 25 X -
Internet Explorer 11 X X
As you can see IE supports both version 2 and 4 (although through Windows own color system) which can explain the situation if you save an image with ICC profile version 4 (I cannot test Android Chrome at the moment).
To save out PNG without ICC from Photoshop use "Save for web" and tick off ICC embedding.
For a more in-depth (sub-link from the test) you can see this article:
Web browser color management guide.
ICC support in Firefox
ICC support in Chrome
ICC support in IE9+

Internet Explorer 10 not showing custom cursor on Windows 8

I am trying to change the mouse cursor in a cross-browser HTML5 webapp.
By simply adding the appropriate CSS everything works fine in all browsers, including IE on Windows 7.
The same webapp in Windows 8 fails to change the cursor, although by inspecting the CSS I can see that the correct class is applied and the browser queries the server for the appropriate .cur file.
Is there any limitation on Windows 8 that I should be aware of?
EDIT
CSS example (note: this works on IE10 Win7, does not work on IE10 Win8. The example should be irrelevant given the question).
.customCursor-move {
cursor: url(/free/images/pointers/move.cur),url(free/images/pointers/move.cur),url("../images/pointers/move.cur"), default !important;
}
The CSS is in free/css.
Internet Explorer cursor css property is buggy : http://reference.sitepoint.com/css/cursor
It could also include IE10. You should try wether to use an absolute or relative path to your .cur file , depending of what you have now.
it also might be helpful :
Note also that the Windows operating system requires the image to be 32 x 32 pixels or smaller although the specifications do allow for larger sizes than this.

Show content depending on Document Mode

Is there a way to show on a web page which browser mode and which document mode is set?
Is this generally possible and is it possible to show/hide some content depending of which mode is switched on?
I would like to use a function to allow upload by drag and drop (see http://blueimp.github.com/jQuery-File-Upload/) but I noticed that this works only when IE is in a specific Document Mode. In case this mode is not switched on I would like to disable the Option to upload by drag and drop.
var j = jQuery.noConflict();
j(document).ready(function(){
/* detect usage of IE Developer Tools using different Mode for Browser and Document */
if(j.browser.msie) {
var browserVersion = j.browser.version.slice(0,j.browser.version.indexOf("."));
var documentVersion = document.documentMode;
if(browserVersion != documentVersion) {
alert("ERROR:\nBrowser Mode and Document Mode do not match!\n\nBrowser Mode: IE"+ browserVersion +".0\nDocument Mode: IE"+ documentVersion +".0");
}
}
});
Courtesy: http://my.opera.com/Schalandra/blog/2012/02/29/how-to-detect-different-browser-mode-and-document-mode-in-ie
Maybe you'll find this answer helpful too.
https://stackoverflow.com/a/623071/903454
You can detect the document-mode:
var mode = document.documentMode;
If the mode is Internet Exlporer 5, it returns five, if it's IE6, it returns 6, and so on.
However, you can force a specific document mode:
<meta http-equiv="X-UA-Compatible" content="IE=[IEVersion]">
Where [IEVersion] is one of the following:
Edge Always the newest version
EmulateIE9 If the doctype is set, the mode is IE9, otherwise IE5
EmulateIE8 See EmulateIE9
EmulateIE7 See EmulateIE9
9 Alway IE9
8 Always IE8
7 Always IE7
5 Always IE5
PS: Your plugin should recognize the mode automatically.
You can use document.documentMode in IE to find out html document
5 The page is displayed in IE5 mode
7 The page is displayed in IE7mode
8 The page is displayed in IE8 mode
9 The page is displayed in IE9 mode

Using getUserMedia/Stream API with iOS 6

I am trying to build a web app that will allow users to use the built in camera on an iPad to take a picture or video of themselves and then post it to Facebook. So far I have had no luck when testing getUserMedia() in Safari for iOS 6 or the Chrome app.
This info graphic shows that it is not supported by Safari with iOS 6 but it should work with Chrome, no?
http://caniuse.com/stream
Any help would be much appreciated.
Currently the only way for mobile Safari to get an image from the camera (or photo roll) is with an input element. It is quite simple:
<input id="image-picker" type="file" accept="image/*" />
Then in js:
$("#image-picker").change( function (event) {
var files = event.target.files;
if (files.length>0) {
// Do something with files[0]
}
});
Chrome for iOS uses identical methods/views for displaying and interpreting HTML, with the exception of a few Safari-specific optimizations. If Safari does not support getUserMedia(), then Chrome cannot support it either unless they build their own port of WebKit for iOS, and even then, it might be a stretch. The functionality you are after may be available through some other means, but not using getUserMedia().
Now Safari supports it starting from IOS 11 & Safari 11.
The namespaces have changed a little as its now mediaDevices prefixed.
Check https://caniuse.com/?search=mediaDevices