theCro Posted January 19, 2008 Author Share Posted January 19, 2008 //FULL SERVER PATH TO THIS FILE -- REPLACE WITH YOUR INFO (ENTIRE PATH MAY DIFFER) $server_path = "/home/zadarsp/public_html"; //PATH TO IMAGES DIRECTORY $img_path = "foto/"; //CONVERT THE IMAGE //PATH TO IMAGEMAGICK: /usr/X11R6/bin/convert (MAY BE DIFFERENT ON YOUR SERVER - REPLACE IF NECESSARY) $tmpMakeIMG = "/usr/local/bin/convert -density 300X300 -quality 100 $geometry $img_crop -colorspace RGB $server_path$img_path$img_start $server_path$img_path$img_end"; $makeIMG = `$tmpMakeIMG`; this is what is in ... its all correct! Quote Link to comment Share on other sites More sharing options...
harley1387 Posted January 20, 2008 Share Posted January 20, 2008 Can you post the entire script for foto.php. If you enter the following URL http://www.zadarsport.com/foto.php?img_start=abc123.jpg&img_end=new.jpg&w=300&h=200&crop=yes, (assuming abc123.jpg doesn't exist on your server) you should at the very least get the following error: ERROR: abc123.jpg file not found! Verify the server_path and img_path variables. Can you also set error reporting to E_ALL at the top of the script for testing: error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
theCro Posted January 21, 2008 Author Share Posted January 21, 2008 Can you post the entire script for foto.php. If you enter the following URL http://www.zadarsport.com/foto.php?img_start=abc123.jpg&img_end=new.jpg&w=300&h=200&crop=yes, (assuming abc123.jpg doesn't exist on your server) you should at the very least get the following error: ERROR: abc123.jpg file not found! Verify the server_path and img_path variables. Can you also set error reporting to E_ALL at the top of the script for testing: error_reporting(E_ALL); ,, there u go <?PHP //CURRENT IMG NAME; DESIRED IMG NAME (OPTIONAL); RESIZE WIDTH (OPTIONAL); RESIZE HEIGHT (OPTIONAL); DESIRED IMG FORMAT (jpg, png, etc.; OPTIONAL); CROP (yes; OPTIONAL) //IF CROPPING IS NOT SET TO yes, WILL RESIZE PROPORTIONALLY TO FIT USING THE WIDTH AND HEIGHT AS MAXIMUMS (IF PROVIDED) //DESIRED IMG NAME WILL OVERRIDE THE DESIRED IMG FORMAT e.g., original.jpg > new.jpg with format set to png WILL CREATE A JPG FILE CALLED new.jpg function convert_img ($img_start, $img_end, $width, $height, $format, $crop) { //FULL SERVER PATH TO THIS FILE -- REPLACE WITH YOUR INFO (ENTIRE PATH MAY DIFFER) $server_path = "/home/zadarsp/public_html"; //PATH TO IMAGES DIRECTORY $img_path = "foto/"; //CHECK IF ORIGINAL FILE EXISTS if (is_file($server_path.$img_path.$img_start)) { //CHECK IF DESIRED IMG NAME IS SPECIFIED if (!$img_end){ //OTHERWISE CHECK IF FORMAT IS SPECIFIED - FORMAT WILL ONLY CHANGE IF IMG_END IS NOT SPECIFIED if ($format){ $img_arr = explode(".", $img_start); $img_end = $img_arr[0].".".$format; } else { $img_end = $img_start; } } //CHECK IF RESIZE WIDTH & RESIZE HEIGHT WERE PROVIDED; ADJUST ACCORDINGLY if (!$width && !$height){ $geometry = ""; } else { if (!$height) { $geometry = "-geometry ".$width; } else if (!$width) { $geometry = "-geometry X".$height; } else { $geometry = "-geometry ".$width."X".$height; } } //CHECK IF CROPPING IS REQUESTED - REQUIRES HEIGHT AND WIDTH TO BE SPECIFIED if ($crop == "yes"){ if (!$width || !$height){ return $error = "ERROR: Specify a width and height or set crop to 'no'"; } $img_size = getimagesize($img_path.$img_start); //CALCULATES ASPECT RATIO TO DETERMINE HOW TO RESIZE THE IMAGE PROPORTIONALLY TO MINIMIZE CROPPING if(($img_size[0]/$img_size[1]) >= ($width/$height)) { $geometry = "-geometry X".$height; } else { $geometry = "-geometry ".$width; } //CURRENTLY CROPS FROM THE CENTER OF THE IMAGE -- TRIMMING EQUAL AMOUNTS (ONLY IF NECESSARY) ON THE TOP/BOTTOM; LEFT/RIGHT //CROPPING OPTIONS FOR THE GRAVITY INCLUDE: NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast (CHANGE IF NECESSARY) $img_crop = "-gravity Center -crop ".$width."X".$height."+0+0"; } else { $img_crop = ""; } //CONVERT THE IMAGE //PATH TO IMAGEMAGICK: /usr/X11R6/bin/convert (MAY BE DIFFERENT ON YOUR SERVER - REPLACE IF NECESSARY) $tmpMakeIMG = "/usr/local/bin/convert -density 300X300 -quality 100 $geometry $img_crop -colorspace RGB $server_path$img_path$img_start $server_path$img_path$img_end"; $makeIMG = `$tmpMakeIMG`; //DISPLAY THE IMAGE OR RETURN ERROR MESSAGE; USE FOR TESTING; DELETE THIS CODE IF NOT REQUIRED if (is_file($server_path.$img_path.$img_end)) { $img_size = getimagesize($img_path.$img_end); return $img = '<IMG SRC="'.$img_path.$img_end.'" border="0" '.$img_size[3].'>'; } else { return $error = "ERROR: There was a problem converting the image!"; } } else { return $error = "ERROR: $img_start file not found! Verify the server_path and img_path variables."; } } //EXAMPLE USAGE -- ONLY UN-COMMENT THE ONE YOU WANT TO USE: //OUTPUTS A FILE THAT IS PROPORTIONALLY RESIZED AND CROPPED TO 200px by 200px CALLED new.jpg //print convert_img ("original.jpg", "new.jpg", "200", "200", "", "yes"); //OUTPUTS A FILE THAT IS PROPORTIONALLY RESIZED TO EITHER 200px by X -OR- X by 200px (DEPENDING ON THE ASPECT RATIO) CALLED new.jpg //print convert_img ("original.jpg", "new.jpg", "200", "200", "", ""); //OUTPUTS A FILE THAT IS PROPORTIONALLY RESIZED TO 200px by X CALLED original.png //print convert_img ("original.jpg", "", "200", "", "png", ""); //OUTPUTS A FILE THAT IS PROPORTIONALLY RESIZED TO 200px by X CALLED original.png (alternate way of accomplishing the above) //print convert_img ("original.jpg", "original.png", "200", "", "", ""); //OVERWRITES THE ORIGINAL FILE AND RESIZES TO X by 200px //print convert_img ("original.jpg", "", "", "200", "", ""); ?> Quote Link to comment Share on other sites More sharing options...
harley1387 Posted January 21, 2008 Share Posted January 21, 2008 You never added the code that calls the function (and all the lines at the bottom are commented out)??? You either have to add the following code to pass vars via a URL or un-comment one of the lines at the bottom. print convert_img ($_GET['img_start'], $_GET['img_end'], $_GET['w'], $_GET['h'], "", $_GET['crop']); Drop it in right above the last line of code and try again. Quote Link to comment Share on other sites More sharing options...
theCro Posted January 22, 2008 Author Share Posted January 22, 2008 thank you. thank you. thank you. thank you. thank you. thank you. thank you. thank you. thank you. thank you. thank you. thank you. my problem is RESOLVED! Mark it as one too! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.