It seems to work when whenever i extend the memory… but this looks like a problem cause i can’t keep extending the memory…. i noticed that it only happens when i upload large images….
I am currently working on wamp on localhost
<?php if (!defined(‘BASEPATH’)) exit(‘No direct script access allowed’);
/**
*
*
* @author Edmond Sebetseba
* @since Version 0.1
* @purpose generate thumbnails.
* @website http://www.mellocube.com/
*/
/*
Instructions:
Load the plugin using:
$this->load->plugin(‘createthumb’);
once loaded, you can call
createThumb($source_file,$destnation_file);
*/
ini_set(“memory_limit”,“12M”);
function createThumb($source,$dest) {
$thumbnail_size = 100;
$size = getimagesize($source);
$width = $size[0];
$height = $size[1];
//image extension
$ext = strtolower(end(explode('.', $source)));
if($width > $height) {
$x = ceil(($width - $height) / 2 );
$y = NULL;
$width = $height;
} elseif($height > $width) {
$y = ceil(($height - $width) / 2);
$x = NULL;
$height = $width;
}
$new_img = ImageCreatetruecolor($thumbnail_size,$thumbnail_size);
if ($ext==‘jpg’)
{
$img = imagecreatefromjpeg($source);
imagecopyresampled($new_img,$img,0,0,$x,$y,$thumbnail_size,$thumbnail_size,$width,$height);
imagejpeg($new_img,$dest,100);
}
if ($ext==‘gif’)
{
$img = imagecreatefromgif($source);
imagecopyresampled($new_img,$img,0,0,$x,$y,$thumbnail_size,$thumbnail_size,$width,$height);
imagegif($new_img,$dest,100);
}
if ($ext==‘png’)
{
$img = imagecreatefrompng($source);
imagecopyresampled($new_img,$img,0,0,$x,$y,$thumbnail_size,$thumbnail_size,$width,$height);
imagepng($new_img,$dest,100);
}
}
?>