Page 1 of 1

Image Resolution

Posted: 2007-06-21T00:57:04-07:00
by zombie_nation
Hi,

First time posting.
Just getting my teeth into imagemagick but having some difficulty.
I have a client site that needs to upload images and produce print quality images with annotations as a standard width / height.
I have grasped the basics of imagemagick in terms of annotating and saving new images but I was hoping for a way to getting the image resolution (dpi) of the uploaded image before I do any annotating.

I am using PHP to do all the work and using exec() to run the command lines I build.
Is there a way to get the resolution and compare that to a pre-defined resolution to see if it advisable to carry on?

Would it be better to use MagickWand for PHP?

Thanks,
Z.

Re: Image Resolution

Posted: 2007-06-21T13:17:04-07:00
by Bonzo
Not the best way to do this; I did have a better way but can not remember how to do it now !

Code: Select all

<?php
function GetGeometry($result)
   {
      global $original_width, $original_height;
      
      $start = strpos($result, "Resolution");
      $result = substr($result, $start);
      $length = strpos($result, "\n");
      $result = substr($result, 10, $length-10); 
      $result = explode("x", $result);
      $original_width = $result[0];
      $original_height = $result[1]; 
   }
   
   $sourcefile = "_imagemagick/sunflower.jpg";
   
   $cmd = "identify -verbose ".$sourcefile; 
	exec("$cmd 2>&1", &$o, $r);

	$result = (join("\n", $o)."\n</pre>\n");

	//echo "<pre>".$result;

	GetGeometry($result);

	echo "Width = ".$original_width;
	echo "<br>Height = ".$original_height."<br>";
?>
You should be able to modify this for your needs.

EDIT: Condensed version

Code: Select all

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

Re: Image Resolution

Posted: 2007-06-26T07:15:09-07:00
by zombie_nation
thanks for that. I never realised there was a verbose command. Really impressed.

Z.