I would like to use ImageMagick's identify within PHP to identify an image! Problem (for me as I'm new to PHP), is how do I return the result(s) that are in an Array? When I run identify /var/www/web1/web/tmp/upload/test.jpg from a SSH session I get this: JPEG 90x69 DirectClass 2kb 0.000u 0:01 All I need the PHP code to returm is the JPEG This is what I have as PHP code till now. Code: <?php exec("identify /var/www/web1/web/tmp/upload/test.jpg"); // the data returned is in an Array. // How do I show the value(s) from the Array? ?>
In your example it seems that JPEG is the first array element so you it is $result[0]. Here's another neat little function that lets you display (multi-)dimensional arrays quite easily: So you could build a script like this:
Thank you... The code looks nice I was just reading about the explode option in PHP, so I made this code; Code: <?php $str=exec("identify /var/www/web1/web/tmp/upload/test.jpg"); $pieces = explode(" ", $str); echo $pieces[0]; // 1st value echo "<br>"; echo $pieces[1]; // 2nd value ?>
But the array returned for: identify /var/www/web1/web/tmp/upload/test.jpg looks like this: /var/www/web1/web/tmp/upload/test.jpg JPEG 125x164 DirectClass 8kb 0.000u 0:01 I only need the JPEG With the explode function I'm breaking the array at every 'space' it finds in the array. I guess I called it an Array, but it's not..?
You could as well use PHP's getimagesize function to find out about the type of an image file: http://www.php.net/manual/en/function.getimagesize.php