0

I am dealing with exif data acquired via php , and I see that the DPI of a scanned image can return 300/1 or 600/1 for example

I am not sure if this is normal but google tells me it is common. I do not know if this means I may see 300/2 (150DPI)

When I get this variable from exif, I want to treat it as a math problem that needs simplifying or in math terms 300 / 1 =300 therefore 300. As it is a string I have no idea how to tell php to simplify the math in the string.

Any ideas?

Mark
  • 39
  • 1
  • 6
  • There are dozens of duplicate questions: https://www.google.com/search?q=php+evaluate+math+expression+site:stackoverflow.com&sa=X&ved=2ahUKEwjRhMfq9engAhWCxIMKHadOAoAQrQIoBDAAegQIChAM&biw=2560&bih=1329 – user229044 Mar 05 '19 at 02:09

1 Answers1

-1

Assuming the string contains something like 300 It sounds like you're looking to cast your string to an integer with something like (int)$exif_string. If it contains something like 300/1, you can use substr($exif_string, 0, 3) to grab only the first three characters.

Once you have an integer variable, you can make your calculations on it:

$dpi = (int)substr($exif_string, 0, 3);
$dpi_value = $dpi / 300;

eval() would be a possible alternative, though I would recommend against this, due to the fact that it can allow arbitrary execution of code.

Obsidian Age
  • 41,205
  • 10
  • 48
  • 71