Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeIgniter/PHP/GD2 Image Manipulation is playing up
    primarykey
    data
    text
    <p>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.</p> <p>So here's the code - _imageformat() is passed the parameters (which I've confirmed to be correct) from CI's Upload Class:</p> <pre><code>function _imageformat($fullpath, $shortpath, $width, $height) </code></pre> <p>{ // We now format the image.</p> <p>// 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); } </p> <p>}</p> <p>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;</p> <pre><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-&gt;load-&gt;library('image_lib', $config); $this-&gt;image_lib-&gt;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-&gt;load-&gt;library('image_lib', $config); $this-&gt;image_lib-&gt;resize(); return $newimage; </code></pre> <p>}</p> <p><strong>What SHOULD happen:</strong> 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).</p> <p><strong>What DOES happen:</strong> In my uploads folder, there are only <strong>TWO</strong> images - the original uploaded file (image.jpg), and the resized file (image_full.jpg). No thumbnail is ever created.</p> <p><strong>What's interesting, however, ** is that if I place the code for the Thumbnail creation <em>first</em>, it generates the thumbnail image but **NOT</strong> the _full (resized) image. </p> <p>So it appears to me that it won't ever run <code>$this-&gt;image_lib-&gt;resize()</code> twice. Why not? Is it some amateur mistake I'm making, or have I missed something obvious?! :P</p> <p>Thanks!</p> <p>Jack</p> <p><strong>Edit:</strong> 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-&gt;_thumbnail()</code> which loaded the library again there. But still the same issue occurred.</p> <p><strong>Edit 2:</strong> I've also tried using <code>$this-&gt;image_lib-&gt;clear()</code> - still no luck.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload