[magick-users] ImageMagick & PHP

chris at sppgo.com chris at sppgo.com
Thu Nov 21 16:49:12 PST 2002


Hi guys,
I've just started using imagemagick in a PHP page. I have an image upload form on the previous page that sends raw artwork in a number of different formats. This artwork needs to be converted to jpg and scaled to fit in a 160x160 box.
I think I'm getting a bit confused with the paths to the images that I'm trying to scale and convert, and what imagemagick returns.
Here's my code, can anyone help?


#############################################################################
//if image has been uploaded:
if($raw_image1_name && substr_count($raw_image1_type, "image")>0){ 

//create new name for raw but keep same extension
$extension=substr($raw_image1_name, -strpos(strrev($raw_image1_name), "."));;
$new_raw_name="$created_id"."_1.$extension";

//copy to raw location and rename according to $current_id
	copy("$raw_image1", "../images/property_images/raw/$new_raw_name");

//insert path into db
$insert_raw_query="update listing set raw_image1='$new_raw_name' where listing_id=$created_id";
$insert_raw_run=mysql_query($insert_raw_query,$conn) or die(mysql_error());

//create web image
$optimised="$created_id"."_1.jpg";	
  $cmd = "/usr/X11R6/bin/mogrify -geometry 160x160 ../images/property_images/raw/$new_raw_name 2>&1;"." convert ../images/property_images/raw/$new_raw_name $optimised";
  exec($cmd, $exec_output, $exec_retval);

  if($exec_retval > 0)
  {
    print "ERROR: $exec_output[0]";
  }
  else
  {
	//copy optimised to new location and write filename to db
		  copy("$raw_image1", "../images/property_images/optimised/$optimised_name");
		  $insert_optimised_query="update listing set image1='$optimised_name' where listing_id=$created_id";
		$insert_optimised_run=mysql_query($insert_optimised_query,$conn) or die(mysql_error());
		
  }
}
#############################################################################



Thanks a million in advance

:o) Chris



More information about the Magick-users mailing list