5 Replies - 391 Views - Last Post: 05 February 2013 - 02:17 PM Rate Topic: -----

#1 Alhazred  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 174
  • Joined: 25-July 07

[codeigniter] The resize function doesn't work properly

Posted 05 February 2013 - 10:46 AM

I have a form with a file field to upload an image, this image must be resized to fit a space on a page.

The upload works correctly, but the resize does't.

Here is how I do the resize


$config['image_library']    = 'gd2';
$config['source_image']     = '.'.$this->config->item('upload_image_base').'/'.'logo_'.$id.'.jpg';
$config['height']           = $this->config->item('logo_height'); //this is 80
$config['width']            = $this->config->item('max_logo_width'); //this is 300
$config['maintain_ratio']   = TRUE;
$config['master_dim']       = 'height';
                
$this->load->library('image_lib', $config);
                
$this->image_lib->resize();




The source image is

Posted Image

This is how CodeIgniter resizes it

Posted Image

As you can see it is not correctly resized, what is the problem? How to solve it?

Is This A Good Question/Topic? 0
  • +

Replies To: [codeigniter] The resize function doesn't work properly

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3369
  • View blog
  • Posts: 11,410
  • Joined: 12-December 12

Re: [codeigniter] The resize function doesn't work properly

Posted 05 February 2013 - 11:59 AM

I assume it might be because you have told it to maintain the ratio, and the resize-proportions are not the same as the original proportions.

This post has been edited by andrewsw: 05 February 2013 - 12:00 PM

Was This Post Helpful? 0
  • +
  • -

#3 Alhazred  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 174
  • Joined: 25-July 07

Re: [codeigniter] The resize function doesn't work properly

Posted 05 February 2013 - 12:43 PM

The sizes provided are the limits to decide on which side to calculate the resize.

In example the source image is 200x80, the function should see that the side which exceeds the dimensions is the height and then it should calculate the new sizes according to the height maintaing the aspect ratio, it doesn't have to create a 300x70 image (in the code I made a mistake, the $config['height'] is 70, not 80)

This post has been edited by Alhazred: 05 February 2013 - 12:44 PM

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3369
  • View blog
  • Posts: 11,410
  • Joined: 12-December 12

Re: [codeigniter] The resize function doesn't work properly

Posted 05 February 2013 - 12:55 PM

Try this:

$this->load->library('image_lib', $config);
$this->image_lib->initialize($config);
$this->image_lib->resize();

Was This Post Helpful? 0
  • +
  • -

#5 Alhazred  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 174
  • Joined: 25-July 07

Re: [codeigniter] The resize function doesn't work properly

Posted 05 February 2013 - 02:09 PM

Same problem, I've written a my own function to resize the images and it works.
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3369
  • View blog
  • Posts: 11,410
  • Joined: 12-December 12

Re: [codeigniter] The resize function doesn't work properly

Posted 05 February 2013 - 02:17 PM

Every programmable object has a correct() method.

$this->image_lib->resize();
$this->image_lib->correct();



...



No they don't, just wishful thinking on my part :) :whistling:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1