[eluser]gRoberts[/eluser]
Well i thought i had fixed it. It seems that this works for the specific image i had but doesn't work for gifs.
Would there be any reason why it wont work?
I have attached the image that doesn't work using GD2 and CI's image lib.
Code:
public function generate($source, $output, $width, $height) {
$size = getimagesize($source);
if($size[0] > $width || $size[1] > $height) {
$src = imagecreatefromjpeg($source);
$original_width = imagesx($src);
$original_height = imagesy($src);
if($original_width > $original_height) {
$new_width = $width;
$new_height = $original_height*($width/$original_width);
} else {
$new_height = $width;
$new_width = $original_width*($width/$original_height);
}
$op_img = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($op_img, $src, 0, 0, 0, 0, $new_width, $new_height, $original_width, $original_height);
imagejpeg($op_img, $output);
} else
copy($source, $output);
}