Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not sure if you were having trouble getting the actual image sizer library to work, or whether you just want to know how to save to three different places with different sizes... assuming you want to do the latter, you probably want to just create a function that does the image sizing stuff for you and then pass in the different height/width/name of directory/etc. that you want... Haven't tested it but it would look something like this:</p> <pre><code>function your_function() { $this-&gt;upload-&gt;initialize($config); $this-&gt;load-&gt;library('upload'); $this-&gt;load-&gt;library('image_lib'); if(!$this-&gt;upload-&gt;do_upload()) { $error = array('error' =&gt; $this-&gt;upload-&gt;display_errors()); $this-&gt;load-&gt;view('submit', $error); } else { $data['upload_data'] = array('upload_data' =&gt; $this-&gt;upload-&gt;data()); $file_name = $this-&gt;upload-&gt;file_name; list($image_width, $image_height) = getimagesize($_SERVER['DOCUMENT_ROOT'].'/website/uploads/original/'.$file_name); $this-&gt;image_resize('115', '181', 'small', $file_name, $image_width, $image_height); $this-&gt;image_resize('300', '400', 'medium', $file_name, $image_width, $image_height); $this-&gt;image_resize('600', '500', 'large', $file_name, $image_width, $image_height); } } private function image_resize($height, $width, $path, $file_name, $image_width, $image_height) { // Resize image settings $config['image_library'] = 'GD2'; $config['source_image'] = $_SERVER['DOCUMENT_ROOT'].'/website/uploads/original/'.$file_name; $config['new_image'] = $_SERVER['DOCUMENT_ROOT']."/website/uploads/$path/$file_name"; $config['maintain_ratio'] = TRUE; $config['width'] = $width; $config['height'] = $height; $config['master_dim'] = 'width'; $this-&gt;image_lib-&gt;initialize($config); if($image_width &gt;= $config['width'] AND $image_height &gt;= $config['height']) { if (!$this-&gt;image_lib-&gt;resize()) { echo $this-&gt;image_lib-&gt;display_errors(); } else { if(file_exists($_SERVER['DOCUMENT_ROOT']."/website/uploads/$path/$file_name")) { list($image_width, $image_height) = getimagesize($_SERVER['DOCUMENT_ROOT']."/website/uploads/$path$file_name"); if($image_height &gt; '115') { $config['source_image'] = $_SERVER['DOCUMENT_ROOT'].'/website/uploads/small/'.$file_name; $y_axis = $image_height - 115; $config['y_axis'] = $y_axis; $config['x_axis'] = 181; $this-&gt;image_lib-&gt;initialize($config); if (!$this-&gt;image_lib-&gt;crop()){ echo $this-&gt;image_lib-&gt;display_errors(); } else { echo "cropped"; } } } } } } </code></pre>
 

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