CodeIgniter/PHP/GD2 Image Manipulation is playing up

soilaybeter

New Member
I have a website going that takes a user's uploaded image, and makes three copies - a 'full' copy to print with (downsized to 1500x1125), a 'web' copy to display online (not coded yet), and finally a thumbnail.So here's the code - _imageformat() is passed the parameters (which I've confirmed to be correct) from CI's Upload Class:\[code\]function _imageformat($fullpath, $shortpath, $width, $height)\[/code\]{ // We now format the image.// First, we check if it is landscape or portrait if ($width >= $height) // It's landscape (or square) { // Now create the full printing image $fullimage = $this->_resize('l', $fullpath, $shortpath, $width, $height); } else // It's portrait { // Now create the full printing image $fullimage = $this->_resize('p', $fullpath, $shortpath, $width, $height); } }function _resize($type, $fullpath, $shortpath, $width, $height) { // Set up the default Image Manipulation config options $config['image_library'] = 'gd2'; $config['source_image'] = $fullpath; $config['maintain_ratio'] = TRUE;\[code\]// Shave the '.jpg' from the end to append some nice suffixes we'll use$newimage = substr($fullpath, 0, -4).'_full'.".jpg";$config['new_image'] = $newimage;if ($type == 'l') // If it's landscape{ $config['width'] = 1500; $config['height'] = 1125;}else if ($type == 'p') // If it's portrait{ $config['width'] = 1125; $config['height'] = 1500; }// Load the image library with the specified parameters, and resize the image! $this->load->library('image_lib', $config); $this->image_lib->resize();// Create a thumbnail from the full image$config['source_image'] = $newimage;$config['new_image'] = substr($fullpath, 0, -9)."_thumb".".jpg";$config['maintain_ratio'] = TRUE;$config['width'] = 150;$config['height'] = 150;$this->load->library('image_lib', $config); $this->image_lib->resize();return $newimage;\[/code\]}What SHOULD happen: In my uploads folder, there are three images - the original uploaded file (we'll call it image.jpg), the resized file (named image_full.jpg), and the thumbnail (named image_thumb.jpg).What DOES happen: In my uploads folder, there are only TWO images - the original uploaded file (image.jpg), and the resized file (image_full.jpg). No thumbnail is ever created.What's interesting, however, ** is that if I place the code for the Thumbnail creation first, it generates the thumbnail image but **NOT the _full (resized) image. So it appears to me that it won't ever run \[code\]$this->image_lib->resize()\[/code\] twice. Why not? Is it some amateur mistake I'm making, or have I missed something obvious?! :PThanks!JackEdit: I should point out that yes, I know I'm loading the \[code\]image_lib\[/code\] library twice. I fathomed this was the only way of passing new parameters to it. I also tried, after resizing the full image, calling \[code\]$this->_thumbnail()\[/code\] which loaded the library again there. But still the same issue occurred.Edit 2: I've also tried using \[code\]$this->image_lib->clear()\[/code\] - still no luck.
 
Back
Top