foucquet Posted December 12, 2011 Share Posted December 12, 2011 When pulling exif data from an image I have pretty much everythiung nailed down except for the Shutter Speed value. When pulled from the image this is returned as:- 'Shutter' => string '0.0015625' Now I know that the actual shutter speed at the time of shooting was 1/640 sec; does anyone have any ideas about how one would convert... 'Shutter' => string '0.0015625' to 1/640 sec... I have been scratching my head over this problem for a few days now and am stiull no wiser Quote Link to comment https://forums.phpfreaks.com/topic/252994-shutter-speed-conversion/ Share on other sites More sharing options...
Adam Posted December 12, 2011 Share Posted December 12, 2011 Since the decimal is basically 'point x of one', you just need to find out how many times it goes into 1: 1 / 0.0015625 = 640 Quote Link to comment https://forums.phpfreaks.com/topic/252994-shutter-speed-conversion/#findComment-1297074 Share on other sites More sharing options...
ManiacDan Posted December 12, 2011 Share Posted December 12, 2011 Note that this won't be 100% accurate in some cases because of the problem of fractions and binary math. You might want to do a "close enough" disclaimer, or make use of the round() function. Quote Link to comment https://forums.phpfreaks.com/topic/252994-shutter-speed-conversion/#findComment-1297089 Share on other sites More sharing options...
ignace Posted December 12, 2011 Share Posted December 12, 2011 To get "around" the binary math problem of close-enough. You can use the BC Math extension. Be sure though that the number is always a string both when storing (or use DECIMAL if your precision is smaller than 65) and manipulating or your result may be off: $var = bcdiv(1, '0.0015625'); // note the quotes Quote Link to comment https://forums.phpfreaks.com/topic/252994-shutter-speed-conversion/#findComment-1297103 Share on other sites More sharing options...
foucquet Posted December 12, 2011 Author Share Posted December 12, 2011 Thanks for all of the suggestions, in the end I used the PHP exif_read_data() function (don't know why I didn't think of it in the first place ) rather than the inbuilt Wordpress function, the PHP function actually returns the exif data as wanted except that one then has to split the DateTime into two variables rather than the one returned, but that's simple Quote Link to comment https://forums.phpfreaks.com/topic/252994-shutter-speed-conversion/#findComment-1297176 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.