Reputation: 6436
According to PHP, the EXIF information for a image is 20/10
for F-number, 51/10
for focal length, and 10/150
for exposure. This is not how these values should look like! It should looks like F/2
for F-number, 5, mm
for focal length, and 1/150
for exposure. These values are just some examples! Please see this link for how I really mean how it should looks like. Note that I will not use any third party software! Just pure PHP.
Is it possible to convert these values (for example 20/10
) to the real values (for example F/2
) in PHP? If yes, how can I convert them?
Thanks in advance.
EDIT
The following code convert 150/10
to 150 seconds which is 2 minutes and 30 seconds. This is wrong because I took the photo with 15 seconds shutter. How can I make it to calculate to the correct amount of seconds?
list($d1, $d2) = str_split('/', 'P1220379.JPG');
if($d1 > 0 AND $d2 > 0) {
$e = $d1 / $d2;
} else {
$e = 'P1220379.JPG';
}
if($e < 1 AND $e > 0) {
$e = '1/'.round(1 / $e, 0).' sekunder';
} else {
$e = round($e, 1).' sekunder';
}
Upvotes: 1
Views: 1988
Reputation: 3080
This is my solution in kotlin if anyone needs
fun convertShutterSpeed(value: String?): String {
if (value.isNullOrBlank()) {
return ""
}
val split = value.split("/")
val ed: Float = split[0].toFloat()
val ed1: Float = split[1].toFloat()
val fl = ed / ed1
return if (ed < 0) {
Math.round(1 / Math.pow(2.toDouble(), fl.toDouble())).toString() + "s"
} else {
"1/" + Math.round(Math.pow(2.toDouble(), fl.toDouble()))
}
}
And here are some tests
@Test
fun convertShutterSpeed() {
assertEquals("1/8", imageExif.convertShutterSpeed("3/1"))
assertEquals("1/10", imageExif.convertShutterSpeed("3321928/1000000"))
assertEquals("1/20", imageExif.convertShutterSpeed("4321928/1000000"))
assertEquals("1/125", imageExif.convertShutterSpeed("6965784f/1000000"))
assertEquals("1/250", imageExif.convertShutterSpeed("7965784/1000000"))
assertEquals("1/320", imageExif.convertShutterSpeed("8321928/1000000"))
assertEquals("1/400", imageExif.convertShutterSpeed("8643856/1000000"))
assertEquals("1/640", imageExif.convertShutterSpeed("9321928/1000000"))
assertEquals("1/800", imageExif.convertShutterSpeed("9643856/1000000"))
assertEquals("1/1000", imageExif.convertShutterSpeed("9965784/1000000"))
assertEquals("2s", imageExif.convertShutterSpeed("-1/1"))
assertEquals("6s", imageExif.convertShutterSpeed("-2584963/1000000"))
}
Values that I got is from Canon images, but it works for other camera models as well.
Upvotes: 0
Reputation: 17364
"drpain" on this link says
Please note that when resizing images with GD and most image processing scripts or applications you will loose the EXIF information.What I did as a workaround is book this information into MySQL before I re-size images.
His little program below
<?php
$camera = cameraUsed("/img/myphoto.jpg");
echo "Camera Used: " . $camera['make'] . " " . $camera['model'] . "<br />";
echo "Exposure Time: " . $camera['exposure'] . "<br />";
echo "Aperture: " . $camera['aperture'] . "<br />";
echo "ISO: " . $camera['iso'] . "<br />";
echo "Date Taken: " . $camera['date'] . "<br />";
?>
does produce these numbers in correct format, according to him
Will display the following, depending on the data:
Camera Used: SONY DSC-S930
Exposure Time: 1/400
Aperture: f/4.3
ISO: 100
Date Taken: 2010:12:10 18:18:45
Upvotes: 2