Welcome Guest, Not a member yet? Register   Sign In
Problem resizing images using resize image manipulation class
#1

[eluser]jwp[/eluser]
I am trying to take an image (16.jpg), resize it creating a new image (161.jpg) while saving the original (16.jpg)

Here is the code:

$config = '';
$config['image_library'] = 'gd2';
$config['source_image'] = 'c:\htdocs\16.jpg';
$config['new_image'] = '161.jpg'; // Don't use a full or absolute path or you will get an error see: http://ellislab.com/forums/viewthread/166359/
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 150;
$config['height'] = 100;

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

if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
} else {
$new_image = $this->image_lib->resize() ;
header ('content-type: image/gif');
readfile('c:\htdocs\161.jpg');
}
$this->image_lib->clear();

When all is said and done 161.jpg exists but 16.jpg is gone replaced with "copy of 16.jpg".

Does anyone know how I can resize and keep 16.jpg?

Thanks,

-J
#2

[eluser]jwp[/eluser]
OK so I figured out what part of the problem was. I already had a file in the directory called "copy of 16.jpg". When I deleted this file I was able to resize the image creating the new file (161.jpg) while keeping the original (16.jpg).

I now have a different issue. I am setting $config['create_thumb'] = FALSE; yet 16_thumb is getting created and I don't need it to be.

Any ideas on this one?

Thanks,

-J
#3

[eluser]Mat-Moo[/eluser]
Try my image_moo library, easier to use.
#4

[eluser]jwp[/eluser]
OK so what needed to be done was to set $config['create_thumb'] = FALSE and $config['thumb_marker'] = ''. Only when I did this did thumbs not get created.

So, the code that works looks like the following:

$config = ''; $errors = '';
$config['image_library'] = 'gd2';
$config['source_image'] = $pathname . $filename ;
$config['create_thumb'] = FALSE;
$config['thumb_marker'] = ''; // for some reason if you don't set this to '' then a thumb might get created when you don't want it to
$config['maintain_ratio'] = TRUE;
$config['new_image'] = $img_large_name; // Don't use a full or absolute or you will get an error see: http://ellislab.com/forums/viewthread/166359/
$config['width'] = 150;
$config['height'] = 150;

$this->load->library('image_lib');
$this->image_lib->clear();
$this->image_lib->initialize($config);
if ( ! $this->image_lib->resize()) {
$errors .= $this->image_lib->display_errors();
}
#5

[eluser]John_Betong_002[/eluser]
I use a slightly different approach:

Pseudo code:
always check to see if the thumbnail exists.
// $this->my_model->_maybe_make_thumb($big_pix, $thumb);

if it exists
then just return
else
try to create thumbnail
log message with the image name and success/failure.

 
Check by deleting the thumbnail to see if it works OK and check the error log.
Good for finding the best size and thumbnail quality, etc
 




Theme © iAndrew 2016 - Forum software by © MyBB