Welcome Guest, Not a member yet? Register   Sign In
How to display image within the table
#1

[eluser]muhax[/eluser]
Hello Smile...

I have the following code:
Code:
$no = 0;
         if($rows != 0)
         {
              foreach ($rows as $row)
              {
                  $rows = $this->category_model->get_all();
                $this->table->set_heading(array('#No.','Category ID','Name','Description', 'Image'));
                  $this->table->add_row(array($no+1, $row->id, $row->name, $row->description, $row->imageLink,
                                              anchor("category/delete_category/$row->id", 'Delete'),
                                              //anchor("category/edit_existing_request/$row->id", 'Edit'),
                                        
                ));
                  $no++;
              }
          }
This code, gets my category table from database and displays it in form of a table. The $row->imageLink contains image link for my category. I need to create thumbnail and instead of plain link display picture?
Any suggestions?
I did go to CI/user_guide/libraries/image_lib.html
but I have no clear understanding on how to utilze it within table?
#2

[eluser]smilie[/eluser]
Untested, but try something like:

Code:
$no = 0;
         if($rows != 0)
         {
              foreach ($rows as $row)
              {
                  $rows = $this->category_model->get_all();
                $this->table->set_heading(array('#No.','Category ID','Name','Description', 'Image'));
                  $this->table->add_row(array($no+1, $row->id, $row->name, $row->description, img($row->imageLink),anchor("category/delete_category/$row->id", 'Delete'),
                                              //anchor("category/edit_existing_request/$row->id", 'Edit'),
                                        
                ));
                  $no++;
              }
          }

Do bare 2 things in mind:
1. img() expects only path to images (not full http://blabla url, but only images/image.jpg);
2. if your image isn't thumnail already, you will need to call img() with array; see http://ellislab.com/codeigniter/user-gui...r.html#img

Cheers,
Smilie
#3

[eluser]teampoop[/eluser]
So this is what I came up with.. It is assuming that $row->imageLink is only the name of the file, (ie: image.jpg) without any path. The reason I am assuming this is because the image_lib wants the machine path to the image, not the URL path...

Code:
$this->load->library('image_lib');
$no = 0;
if($rows != 0)
{
    foreach ($rows as $row)
    {
        $rows = $this->category_model->get_all();

        // IMG MANIPULATION...
        $config['image_library'] = 'gd2';
        $config['source_image']    = '/path/to/image/'.$row->imageLink;
        $config['new_image'] = 'path/to/image/thumb_'.$row->imageLink;
        $config['create_thumb'] = TRUE;
        $config['maintain_ratio'] = TRUE;
        $config['width']     = 75;
        $config['height']    = 50;
        $this->image_lib->initialize($config);
        $this->image_lib->resize();
        $this->image_lib->clear();

        // TABLE CREATION
        $this->table->set_heading(array('#No.','Category ID','Name','Description', 'Image'));
        $this->table->add_row(
            array(
                $no+1,
                $row->id,
                $row->name,
                $row->description,
                img('thumb_'.$row->imageLink),
                anchor("category/delete_category/$row->id", 'Delete'),
                anchor("category/edit_existing_request/$row->id", 'Edit'),
                                        
            )
        );
        $no++;
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB