Welcome Guest, Not a member yet? Register   Sign In
Problem with resizing images
#1

[eluser]BrainCatcher[/eluser]
Hi there,

Got a problem with resizing images. When initiated the image_lib library with the config option 'create_thumb' set to 'true' it wordks like charm. But i don't need any thumbnails. Se when i do set the option 'create_thumb' to 'false' it doesn't make a neat resized image. It creates i big black area within the height and width of the original picture and in the upper left corner is the resized version of the picture. All in one picture.
The used format is an jpg.

Here's the code that initiates it from the controller:

Code:
$settings['maintain_ratio'] = TRUE;
    $settings['image_library'] = 'gd2';
    $settings['create_thumb'] = TRUE;
    $settings['quality'] = '70%';
    $settings['width'] = 100;
    $settings['height'] = 100;
    $settings['source_image'] = 'uploads/pasfoto/'.$filename['file_name'];

        $this->load->library('image_lib', $settings);
        $this->image_lib->resize();
    
            if ( ! $this->image_lib->resize())
            {
                echo $this->image_lib->display_errors();
            }else{
                
            $this->personeel_model->save_cursist_pasfoto($id, $filename['file_name']);
            }

Is there someone who can help me, with this? Otherwise i have to delete thumb pictures as well..

Grtz BrainCatcher

ps. Did i mentioned before?: U R Great!!
#2

[eluser]Flemming[/eluser]
not sure that this would cause a problem but you're resizing the image twice ...

Code:
$this->image_lib->resize();
    
            if ( ! $this->image_lib->resize())
#3

[eluser]BrainCatcher[/eluser]
Yep you're right. I didn't look at it that way...Just tested it out and lookin good!!

Thnx ;-P
#4

[eluser]Flemming[/eluser]
so that was all that was wrong?
#5

[eluser]BrainCatcher[/eluser]
Yes it was. Probably i didn't realize when i wrote the code, that with the if-statement I did execute the resizing again. I ran a test with several different images. And it looks like it did solve the problem, which wasn't really a problem related to CI's image_lib library but to the coder. In fact, most of the time, that was me.....

Thnx again
#6

[eluser]Flemming[/eluser]
Excellent! Glad you got it sorted!
#7

[eluser]behnampmdg3[/eluser]
Mine doesnt work : (

Code:
public function resize($photo)
  {
   $config['image_library'] = 'gd2';
   echo $config['source_image'] = $photo;
   echo $config['new_image'] = 'new.jpg';
   //$config['create_thumb'] = TRUE;
   $config['maintain_ratio'] = TRUE;
   $config['width'] = 75;
   $config['height'] = 50;
    
   $this->load->library('image_lib', $config);
    
   //$this->image_lib->resize();
   if ( ! $this->image_lib->resize())
    {
     $e = $this->image_lib->display_errors();
     print_($e);
    }
   else
    {
     //echo "resized";
    }
  }
#8

[eluser]behnampmdg3[/eluser]
Mines resize() function is not resizing![I appreciate any help! code]<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Gallery extends CI_Controller
{

public function index()
{
$data['title'] = "Gallary Page";
$data['upload_data']="";
$this->load->vars($data);
if($this->input->post('submit'))
{
$this->do_upload();
}
$this->load_photos();
$this->view_things();
}

function do_upload()
{
$config['upload_path'] = 'uploads/';
$this->load->model('add_photo_model');
$data['new_photo'] = $this->add_photo_model->new_photo_name();
$config['file_name'] = $data['new_photo'];
$config['overwrite'] = TRUE;
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);

if (!$this->upload->do_upload())
{
$data['upload_data'] = $this->upload->display_errors();
$this->load->vars($data);
}
else
{
$photo['details']= array('upload_data' => $this->upload->data());
$this->add_photo_model->add($data['new_photo']);

$data['upload_data'] = "The photo has been uploaded successfully";
$this->load->vars($data);
$this->resize($data['new_photo']);
}
}

public function resize($photo)
{
$config['image_library'] = 'gd2';
echo $config['source_image'] = $photo;
echo $config['new_image'] = 'uploads/new.jpg';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 50;

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

//$this->image_lib->resize();
if ( ! $this->image_lib->resize())
{
$e = $this->image_lib->display_errors();
print_($e);
}
else
{
//echo "resized";
}
}

public function load_photos()
{
$this->load->model('load_photos_model');
$photos = $this->load_photos_model->check();
if($photos)
{
$photos_num_rows=0;
foreach($photos as $row)
{
$photos_num_rows++;
$data['photos'][]=$row->photo;

}
$data['photos_message'] = "There are ".$photos_num_rows." photos uploaded so far";
$this->load->vars($data);
return true;
}
else
{
$data['photos_message'] = "There are no photos uploaded yet!";
$this->load->vars($data);
}
}

public function view_things()
{
$this->load->view('header_view');
$this->load->view('gallery_view');
$this->load->view('footer_view');
}
}
[/code]
#9

[eluser]Flemming[/eluser]
hi,

I can see that you are echoing out some debugging info in: public function resize($photo), so what useful info is that displaying?
#10

[eluser]behnampmdg3[/eluser]
[quote author="Flemming" date="1352198161"]hi,

I can see that you are echoing out some debugging info in: public function resize($photo), so what useful info is that displaying?[/quote]Hey I sort it out! I had to add this:
Code:
$this->image_lib->initialize($config);




Theme © iAndrew 2016 - Forum software by © MyBB