ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Change color of image pad during crop

September 20, 2013 1:42pm

Subscribe [1]
  • #1 / Sep 20, 2013 1:42pm

    SkiOne

    16 posts

    I have the following code snippet that does what I want, it resizes and crops images to certain sizes, if the image has a different aspect ration it will pad that image. The problem is when I do that it gets padded with a black background, I need it to be white. I don’t know how to set this:

    if (!file_exists($new_filename) || 1==1) {
    copy($row['photo'],$new_filename);
    $this->CI->load->library('image_lib');
    if ($row['width']>$device_params['width'] || $row['height']>$device_params['height']) {
    $config['image_library'] = 'gd2';
    $config['source_image'] = $new_filename;
    $config['maintain_ratio'] = TRUE;
    $config['quality'] = '40%';
    if ($scale) {
    $device_params['height'] = ($scale / 100) * $device_params['height'];
    $device_params['width'] = ($scale / 100) * $device_params['width'];
    }
      $config[‘height’] = $device_params[‘height’];
      $config[‘width’] = $device_params[‘width’];
      $config[‘master_dim’] = ‘height’;
      if ($row[‘width’]<$row[‘height’]) {
    $config['rotation_angle'] = '270';
    $config['master_dim'] = 'height';
    if (strtolower(substr($new_filename,-3))=='jpg') {
    $this->CI->image_lib->rotate();
    }
      } else {

    }

      $this->CI->image_lib->initialize($config);

      $this->CI->image_lib->resize();
      $this->CI->image_lib->clear();
      unset($config);
      }

      if ($device_params[‘crop’]) {

    $config['image_library'] = 'gd2';
    //$config['library_path'] = '/usr/bin/';
    $config['source_image'] = $new_filename;
    $size = getimagesize($new_filename);
    //var_dump($size);
    $x_axis = $size[0]/2-($device_params['width']/2);
    $y_axis = $size[1]/2-($device_params['height']/2);
    //echo $x_axis.'-'.$y_axis;
    //die();
    $config['maintain_ratio'] = FALSE;
    $config['height'] = $device_params['height'];
    $config['width'] = $device_params['width'];
    $config['y_axis'] = $y_axis;
    $config['x_axis'] = $x_axis;
    $config['master_dim'] = 'auto';
    $this->CI->image_lib->initialize($config);
    if ( ! $this->CI->image_lib->crop())
    {
    $data['output']['status'] = 0;
    $data['output']['message'] = $this->CI->image_lib->display_errors();
    }

      }
      }

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases