Reading the imagemagick image data into a php variable

<?php

function GetGeometry$result ){ 
global 
$original_width$original_height
$start strpos$result"Geometry" ); 
$result substr$result$start ); 
$length strpos$result"\n" ); 
// Uncomment the line below to find some information required later in the code
//print $start." -> ".$length."<br>"; 
$result substr$result10$length-10 ); 
$result explode"x"$result ); 
$original_width $result[0]; 
$original_height $result[1]; 


// Reads all the image data into an array.
// The width and height are seperated out using the function above 
$sourcefile "../original_images/sunflower.jpg"
$cmd "identify -verbose ".$sourcefile
exec"$cmd 2>&1", &$o$r ); 
$return = ( "\n<pre>\n".join"\n"$o )."\n</pre>\n" ); 

$answer GetGeometry$return ); 

echo 
"Original width = ".$original_width."<br>"
echo 
"Original height = ".$original_height."<br>"

?>

Output:
Original width = 400
Original height = 300+0+0



Getting the info without the formatting function above

<?php

$sourcefile 
"../original_images/sunflower.jpg"
$cmd "identify -verbose ".$sourcefile
exec"$cmd 2>&1", &$o$r ); 
$return = ( "\n<pre>\n".join"\n"$o )."\n</pre>\n" ); 

$start strpos$return"Resolution" ); 
$result substr$return$start ); 
$length strpos$result"\n" ); 
$result substr$result12$length-12 ); 
$result explode"x"$result ); 
$Resolution $result[0]."x".$result[1]; 
echo 
"Resolution = ".$Resolution

?>

Output: Resolution = 72x72



Using the built in ImageMagick format function to select the info required; the problem is it displays the information even if you do not want it to.

<?php

$sourcefile 
"../original_images/sunflower.jpg";
echo 
"File size = ";
$answer system("identify -format \"%b\" $sourcefile"); 
?>

Output: File size = 38439


<?php
$sourcefile 
"../original_images/sunflower.jpg"
print 
"Date and time taken = ";
$answer_exif system("identify -format \"%[EXIF:DateTime]\" $sourcefile");

?>

Output: Date and time taken = 2006:07:29 16:10:30


Another method where the width and height are read into a variable WITOUT displaying.

<?php
$Image_dimensions 
exec("convert ../original_images/sunflower.jpg -format '%wx%h' info:- ");
?>

Yet another method this time the information is read into a variable and not displayed unless asked for.

<?php
exec
('identify -format "%[EXIF:DateTime]" ../original_images/sunflower.jpg'$a);
echo 
"Date and time taken = ".$a[0];

?>

Output: Date and time taken = 2006:07:29 16:10:30