Welcome Guest, Not a member yet? Register   Sign In
How to create multiple image copies with image resize(height and width) in single image upload
#2

[eluser]Bruno França[/eluser]
You can make auxiliar functions in your controller that initialize the image manipulation functions every time that it's called...
See this:
Code:
class MyClass extends CI_Controller
{
  /* Your code */

  /* Image watermark */
  function _img_watermark($imagem)
  {
   $config_wtm = array();
   $config_wtm['image_library']  = 'gd2';
   $config_wtm['source_image']  = $imagem;
   $config_wtm['wm_type']    = 'overlay';
   $config_wtm['wm_vrt_alignment'] = 'bottom';
   $config_wtm['wm_hor_alignment'] = 'right';
   $config_wtm['wm_hor_offset']  = 20;
   $config_wtm['wm_vrt_offset']  = 20;
   $config_wtm['wm_x_transp']   = 1;
   $config_wtm['wm_y_transp']   = 1;
   $config_wtm['wm_overlay_path']  = $this->config->item('arquivos_pasta') . $this->config->item('marcadagua');;
   $this->image_lib->initialize($config_wtm);
   if ( ! $this->image_lib->watermark())
   {
    return $this->_errors = $this->image_lib->display_errors('<div class="message error"><p>', '</p></div>');
   }
   $this->image_lib->clear();
   return TRUE;
  }

  /* Image Thumb */
  function _img_thumb($imagem)
  {
   $config_thumb['image_library']  = 'gd2';
   $config_thumb['source_image']  = $imagem;
   $config_thumb['maintain_ratio'] = true;
   $config_thumb['width']    = $this->config->item('thumb_largura');
   $config_thumb['height']   = $this->config->item('thumb_altura');
   $this->image_lib->initialize($config_thumb);
   if ( ! $this->image_lib->resize())
   {
    return $this->_errors = $this->image_lib->display_errors('<div class="message error"><p>', '</p></div>');
   }
   $this->image_lib->clear();
   return TRUE;
  }
}

And... In your controller action, you can use that functions many times as you want. For example:

Code:
/* After image upload */
if ($this->_img_resize($uploaded_image1)) log_message('debug', ' -- Redimensionada');
if ($this->_img_resize($uploaded_image2)) log_message('debug', ' -- Redimensionada');
if ($this->_img_watermark($uploaded_image1)) log_message('debug', ' -- Marca dagua inserida');

I hope this helps.


Messages In This Thread
How to create multiple image copies with image resize(height and width) in single image upload - by El Forum - 02-02-2012, 06:08 AM



Theme © iAndrew 2016 - Forum software by © MyBB