[eluser]Unknown[/eluser]
I have a queue cropping and resizing images with the below function, and the image-manuplation library keeps returning the error "The Path to the image is not correct. Your server does not support the gd function required to process this type of image"
I know that GD is installed on the server, and the weird part is, this exact code was running on my os x local machine running apache, but this error turns up when I run the application on the production servers.
Code:
function crop_photo($filename, $width, $height, $thumbname)
{
$this->load->library('image_lib');
// get input width & height
$filelocation = './uploads/' . $filename;
//$filelocation = $_SERVER["DOCUMENT_ROOT"] . '/uploads/' . $f
if ( ! function_exists('imagecreatefromjpeg')) {
echo 'doesnt exist';
}
$img = getimagesize($filelocation);
$imgsize = Array('width'=>$img['0'], 'height'=>$img['1']);
// prepare filename
$filename = explode('.', $filename);
$filename = $filename[0];
// image manipulation config
//
if ($imgsize['width'] < $imgsize['height']) {
// image is taller than wide
$target['width'] = $imgsize['width'];
$target['height'] = ($height / $width) * $imgsize['width'];
//
} elseif ($imgsize['width'] > $imgsize['height']) {
// taller than wide
$target['height'] = $imgsize['height'];
$target['width'] = ($width / $height) * $imgsize['height'];
} else {
if ($width < $height) {
// input image is square
// target image is taller than it is wide
$difference = $width / $height;
$thedifference = $imgsize['height'] - ($imgsize['height'] * $difference);
$target['height'] = $imgsize['height'];
$target['width'] = $imgsize['height'] * $difference;
} elseif ($width > $height) {
// input image is square
// target image is wider than it is tall
$difference = $height / $width;
$thedifference = $imgsize['width'] - ($imgsize['width'] * $difference);
$target['width'] = $imgsize['width'];
$target['height']= $imgsize['width'] * $difference;
} else {
// input image is square
// target image is square
// no cropping necessary
$target['height'] = $imgsize['height'];
$target['width'] = $imgsize['width'];
}
}
//print_r($target);
// round out target results after all that math
//
$config['image_library'] = 'gd2';
$config['source_image'] = './uploads/' . $filename . '.jpg';
$config['maintain_ratio'] = false;
$config['width'] = round($target['width']);
$config['height'] = round($target['height']);
$config['x_axis'] = round(($imgsize['width'] / 2) - ($config['width'] / 2));
$config['y_axis'] = round(($imgsize['height'] / 2) - ($config['height'] / 2));
$config['new_image'] = './uploads/' . $filename . '_' . $thumbname . '.jpg';
// output image for next operation
$newimage = $config['new_image'];
//
$this->image_lib->initialize($config);
//
if ( ! $this->image_lib->crop()) {
echo $this->image_lib->display_errors();
} else {
// KEEP GOING !
}
// KEEP GOING!
//
$img = getimagesize($newimage);
$imgsize = Array('width'=>$img['0'], 'height'=>$img['1']);
//
unset($config);
$config['image_library'] = 'gd2';
$config['source_image'] = $newimage;
$config['maintain_ratio'] = true;
$config['width'] = $width;
$config['height'] = $height;
//
$this->image_lib->clear();
$this->image_lib->initialize($config);
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
} else {
$newimage = explode('/', $newimage);
$newimage = $newimage[2];
//$newimage = explode('.', $newimage[2]);
//$newimage = $newimage[0] ;
return $newimage;
}
}