Carousel: shutter speed values from EXIF data are not properly displayed
Steps to reproduce:
- Take a picture with a shutter speed of 1/1250 (0.0008)
- Create a gallery with that image on a site running Jetpack and Carousel
- The Carousel view will display 1/501s instead of 1/1250s

Reported in 1863866-t
Did you investigate this one any more yet? Were you able to duplicate on a test blog?
Yes, I was able to duplicate.
Yeah, I've seen incorrect shutter speeds displayed using Carousel on my website that is being developed, but on other websites too. Typically, shutter speeds of 1/x are displayed as 1/(x+1) e.g 1/500 s would be displayed as 1/501 s.
My simple fix for that: In modules\carousel\jetpack-carousel.js, change the shutterSpeed function to:
shutterSpeed: function(d) {
if (d >= 1) {
return Math.round(d*10)/10 + 's';
}
return '1/' + Math.round(1/d) + 's';
},
This allows for 1 decimal with shutter speeds >= 1 s (e.g. "1.3 s") and returns the correct answer for shutter speeds below 1 s. Is this too simple? Am I missing something?
edit: I know that this does not allow for shutter speeds such as "2/3 s", but from my experience, most digital photo equipment works with standardized shutter speeds anyway, so any shutter speed will be under the form 1/x. If you want to support other formats, you'd have to change the function to something along the lines that are shown here: http://stackoverflow.com/questions/14783869/convert-a-decimal-number-to-a-fraction-rational-number In terms of carousel, that would be something like
shutterSpeed: function(d) {
if (d >= 1) {
return Math.round(d*10)/10 + 's';
}
var df = d, ld = 0, bot = 1, top;
var limit = 1e3;
var tol = 1/1e6;
while (limit-- > 0) {
df = 1 / (df - Math.floor(df));
var td = bot;
bot = Math.floor(bot * df + ld);
ld = td;
top = Math.ceil(d * bot);
if (Math.abs(top/bot - d) < tol) {
break;
}
}
return top + '/' + bot + 's';
},
I did not test this! It is a transcription of the iterative version from the link above translated to carousel variable names.
edit 2: I did test it by now and even though it works, it may give some really wonky values for top and bot (e.g. a shutter speed of "7/32" would give an approached result of "746335165520682/3411817899523117" which is very close, but not very pretty...)
Also mentioned in 1931523-t (note: I removed the user's URLs and have informed them to comment here if they so desire):
(img URL): Nikon D700, 105mm, f/7.1, 1/167s shutter speed. The real shutter speed is 1/250s. The same happens with a different camera (Canon IXUS) (img URL): shutter speed shown by jetpack 1/502s, original shutter speed 1/320s. Here also the is shown wrong with f/5.8. The real value is f/5.6
I'm not sure if changing the title is correct but I assumed that the data source are the exif metadata of the pictures. I guess there is no other possible source for this kind of data. The shutter speed is most times wrong, the aperture value is often correct but not always. The original and wrong values are too different for a rounding problem 1/167 -> 1/250. And with a rounding problem it would in the range of 1/500s always show p.e. 1/501s but not sometimes 1/502s. But I do not know the program code and therefore could be completely wrong.
In the case mentioned in the first post of this topic, the problem seems to be that the "limit" variable allows only for 1000 iterations. If it is increased to e.g. 1e5, the code seems to return the right result.
However, in the case reported in the other issue, I suspect another format of the EXIF values due to different camera brands. Could I get the user's URLs that were removed to verify this?
Of course I can provide you with the URLs. But unfortunately for any reason the exif information is removed on pictures which are downloaded. That's an disadvantage and I do not know if that can be changed. But anyway, if you need the original pictures I can send them to you if necessary.
I have two kinds of pictures. One is taken with a Nikon D700. The Exif version is 2.20. The other one is taken with a Canon IXUS 850. Therefore I have to have a look in the pictures to see the exif version.
If you need anything from me please let me know.
Actually, I was thinking more of a website where the pictures are embedded with carousel, but I don't know if that exists for those pictures. But the original pictures would also do for some trials on my local installation.
Of course, there's my site (http://www.gruhland.de) where you can have a look. The missing exif on downloaded imges has been solved. I use sometimes a watermark plugin which rewrites the images with watermark but drops the exif info.
OK, so the shutter speed seems not to be a problem with the EXIF data. It's a problem with the algorithm and the restriction imposed by the "limit" variable.
If the algorithm is to be kept as similar as possible to the existing one, I'd suggest to move from a maximum number of iterations limitation to a maximum error tolerance limitation:
shutterSpeed: function(d) {
if (d >= 1) {
return Math.round(d) + 's';
}
var df = 1, top = 1, bot = 1;
var tol = 1e-8; // seems to allow for d > 1e-4
while (df !== d && Math.abs(df-d) > tol) {
if (df < d) {
top += 1;
} else {
bot += 1;
top = parseInt(d * bot, 10);
}
df = top / bot;
}
if (top > 1) {
bot = Math.round(bot / top);
top = 1;
}
if (bot <= 1) {
return '1s';
}
return top + '/' + bot + 's';
},
The problem with this is to define the tolerance and the number of iterations needed. For the 1/250 s shutter speed mentioned above, the algorithm needs 497 iterations to return the correct shutter speed (versus using the full 1000 iterations and returning a bad result with the current algorithm). However, for quicker shutter speeds, the number of iterations can very easily surpass 1000. In my quick test with a theoretical shutter speed of 1/9999 (and a tolerance of 1e-8), the algorithm needed 19'995 iterations to return the correct result (with a random 4-digit shutter speed of 1/4963, it needed 9923 iterations). On my desktop computer, that was very quick, but I don't know how mobile terminals would respond to this. I did not try to do a sensitivity study on the tolerance and iterations parameters, but this would be a quick and easy way to fix it.
//Edit: I just looked at the aperture issue that was mentioned. I looked for an image on your site that showed an aperture of 5.8 and found one of a pilot boat taken on a Canon IXUS. However, the metadata in that file effectively states an aperture of 5.8 (as in the "F Number" EXIF tag). So the number displayed in Carousel seems correct and I can't see an error there.
I'm stupid and have not yet looked into the plugin. Can I fix that by myself or will it be fixed maybe in one of the next updates?
You could fix that yourself by replacing the "shutterSpeed" function in "jetpack-carousel.js", but I would not recommend it, because every update that does not include a correction will overwrite your custom function again. So we'll have to wait until the developers chose a fix. I was writing a pretty deeply customized wordpress theme when I came across that issue and that's why I looked into it, but I'm not a developer of jetpack and/or carousel.
Thanks a lot for your help! I try to fix it roughly by myself and hopefully in the next updates it will be fixed by the developers.
@gruhland If you fix it for yourself, please feel free to submit a pull request! If you're not sure how, we'd be delighted to walk you through the process one-on-one, and get your changes reviewed quickly. :)
Due to the fact that I never have worked with github I'm not sure what you mean with a pull request. I've fixed my (shutterspeed)problem for the moment as shown by @Luegge above in this thread (thanks for that). The aperture problem is still unsolved.
@Luegge I'm sorry about the mentioned aperture problem. It seems I made a mistake. Depending on the used programs there is an "aperture" value shown and also sometimes a "aperture min." value. I only saw "aperture" but it must have been the "aperture min." value which is slightly different (f/5.6 instead of f/5.8). Sorry again!
I've worked with github before and I'll probably try to integrate my fix by tomorrow (local time).
Concerning the aperture issue, can you give me a link to an image on your site where it is happening? I'll have a look at the metadata. On Sep 4, 2014 4:57 PM, "Goetz" [email protected] wrote:
Due to the fact that I never have worked with github I'm not sure what you mean with a pull request. I've fixed my (shutterspeed)problem for the moment as shown by @Luegge https://github.com/Luegge above in this thread (thanks for that). The aperture problem is still unsolved.
— Reply to this email directly or view it on GitHub https://github.com/Automattic/jetpack/issues/692#issuecomment-54489410.
@Luegge Aperture problem is "solved". Please look at my last post just some minutes ago.
Just saw your comment, so disregard that last part 😊
It's fine to get such a good and fast support. Thanks again! :-)