I wrote this code but it just returns a black image? Some variable problem somewhere?
Here's the stuff I'm passing to it:
echo"\n <img src='test.php' alt='Taxi' />";
test.php
$gallery->cookieCutter(30, 130, 309, 244, "images/taxi.jpg");
function
function cookieCutter($top_x, $top_y, $bottom_x, $bottom_y, $source_image)
{
global $error, $config;
$final_width = $bottom_x - $top_x;
$final_height= $bottom_y - $top_y;
// Find out what type of image it is (by the file extension)
if (preg_match("/.jpg/i", "$source_image")) $format = 'image/jpeg';
else if (preg_match("/.gif/i", "$source_image")) $format = 'image/gif';
else if (preg_match("/.png/i", "$source_image")) $format = 'image/png';
else $error->addError("Image type not supported.");
// Find out the image size of the original image
list($source_width, $source_height) = getimagesize($source_image);
// Create the blank canvas for the new image to be copied into
$image_destination = imagecreatetruecolor($final_width, $final_height);
// Assign $format; with image type
switch($format)
{
case 'image/jpeg':
$path_image = imagecreatefromjpeg($source_image);
break;
case 'image/gif';
$path_image = imagecreatefromgif($source_image);
break;
case 'image/png':
$path_image = imagecreatefrompng($source_image);
break;
}
// Perform the transplant from the original image to the new image
imagecopyresized($image_destination,$path_image,$top_x,$top_y,$bottom_x,$bottom_y,$final_width,$final_height,$source_width,$source_height);
// Save the image, check what format it is first!
switch($format)
{
case 'image/jpeg':
imagejpeg($image_destination);
break;
case 'image/gif';
imagegif($image_destination);
break;
case 'image/png':
imagepng($image_destination);
break;
}
}
Thanks for any help, it is appreciated!