Welcome Guest, Not a member yet? Register   Sign In
image resize - can't generate a thumb
#1

[eluser]v1ctoria[/eluser]
Hello Everybody !
After having 2hours on it, I need your help for an image resize which is actually not working and I don't know why...

My controller
Code:
<?php
class Gallery extends CI_Controller {
    
    function index() {
        
        
        if ($this->input->post('upload')) {
        $this->gallery_model->do_upload();
              
        }
        
        $data['images'] = $this->gallery_model->get_images();
        
                                   $this->layouts->set_title('About');
                                   $this->layouts->add_aside('login_form');
                                   $this->layouts->view('gallery_view', $data);
        
    }
    
}

My model
Code:
<?php
class Gallery_model extends CI_Model {
    
    var $gallery_path;
    var $gallery_path_url;
    
    function __construct() {
        parent::__construct();
        
        $this->gallery_path = realpath(APPPATH . '../images');
        $this->gallery_path_url = base_url().'images/';
    }
    
    function do_upload() {
        
        $config = array(
            'allowed_types' => 'jpg|jpeg|gif|png',
            'upload_path' => $this->gallery_path,
            'max_size' => 2000
        );
        
        $this->load->library('upload', $config);
        $this->upload->do_upload();
        $image_data = $this->upload->data();
        
        $data = array(
            'source_image' => $image_data['full_path'],
            'new_image' => $this->gallery_path . '/thumbs/newimage.png',
            'create_thumb' => TRUE,
            'maintain_ration' => true,
            'width' => 150,
            'height' => 100
        );
        
        $this->load->library('image_lib', $data);
        $this->image_lib->resize();
        
    }
    
    function get_images() {
        
        $files = scandir($this->gallery_path);
        $files = array_diff($files, array('.', '..', 'thumbs'));
        
        $images = array();
        
        foreach ($files as $file) {
            $images []= array (
                'url' => $this->gallery_path_url . $file,
                'thumb_url' => $this->gallery_path_url . 'thumbs/' . $file
            );
        }
        
        return $images;
    }
    
}

And just in case, this is my view is you want to test quickly :

Code:
<div id="gallery">
        &lt;?php if (isset($images) && count($images)):
            foreach($images as $image):    ?&gt;
            <div class="thumb">
                <a href="&lt;?php echo $image['url']; ?&gt;">
                    <img src="&lt;?php echo $image['thumb_url']; ?&gt;" />
                </a>                
            </div>
        &lt;?php endforeach; else: ?&gt;
            <div id="blank_gallery">Please Upload an Image</div>
        &lt;?php endif; ?&gt;
    </div>
    
    <div id="upload">
        &lt;?php
        echo form_open_multipart('gallery');
        echo form_upload('userfile');
        echo form_submit('upload', 'Upload');
        echo form_close();
        ?&gt;        
    </div>

The upload is totally fine, but the resize is not working and I tried so many things to get it done, but no one worked.

Thank you all for your help Smile
#2

[eluser]Zero-10[/eluser]
Code:
'new_image' => $this->gallery_path . '/thumbs/newimage.png',

I'm not a proficient programmer but I'd assume that'/thumbs/newimage.png', should be '/thumbs/',

does that work for you? Oh and don't forget to chmod your gallery folders to 777
#3

[eluser]v1ctoria[/eluser]
Oh the line is not working without the image name, it was just a try that I forgot to erase.

The thing is, I have this code from a tutorial actually based on an older version of codeigniter which is working absolutely fine.

Can't understand why this is not working ...
#4

[eluser]d1a8lo24[/eluser]
Make the following change on the configuration:

Code:
// CHange this
'maintain_ration' => true,

// To this
'maintain_ratio' => true,

Second is just a suggestion on what I think you are trying to do. If you are uploading images from this form to store and display then on the array for resizing and creating the new thumbnail image you should dynamically change the name otherwise you will replace the thumbnail every time but if that is the intention then there shouldn't be a problem.

Aside from that also check your error logs to see if there are some errors.
#5

[eluser]d1a8lo24[/eluser]
Also if your image folder is inside the applications folder make sure you change the following:

Code:
// From this
$this->gallery_path = realpath(APPPATH . '../images');

// To this
$this->gallery_path = realpath(APPPATH . 'images/');

// And if your folder is nested in another folder then make sure the path is correct
$this->gallery_path = realpath(APPPATH . 'path/to/image/folder/');
#6

[eluser]v1ctoria[/eluser]
Concerning the ratio, no changes appeared.

For the path, everything is fine because the upload is working and in my view I've got the correct full image displaying.


I tried to echo every single image properties and all seems good for this resize, but it's still not working ...
#7

[eluser]d1a8lo24[/eluser]
Ok I did a quick test on my setup and i'm using the latest CI 2.0.2 and I'm running a wamp server with php 5.3

So for the quick test using your code I created 1 controller that will do everything and i did change a few things but everything works.

Code:
class Testing extends CI_Controller {
    
    function index()
    {
                
          if ($this->input->post('upload')) {
          $this->upload();
              
          }
        
          $data['images'] = $this->get_images();

        $this->load->view('testing');        
      }
    
    function upload()
    {
        $gallery_path = './images2/';
        
        $config = array(
            'allowed_types' => 'jpg|jpeg|gif|png',
            'upload_path' => $gallery_path,
        );
        
        $this->load->library('upload', $config);
        
        $this->upload->do_upload();
        
        $image_data = $this->upload->data();
        
        $data = array(
            'source_image' => $image_data['full_path'],
            'new_image' => $gallery_path . '/thumbs/',
            'create_thumb' => TRUE,
            'maintain_ration' => TRUE,
            'width' => 150,
            'height' => 100
        );
        
        $this->load->library('image_lib', $data);
        $this->image_lib->resize();
    }
}
A few things as I mention before when specifying an image in the re size configuration the new uploaded image thumbnail will replace that image but removing the name and just leaving the folder will create a new image for each image uploaded.

So you can do a quick try, make sure you create the folders first on the root if you use my paths otherwise you can change them.

So I was able to upload and made a re size copy of the image a thumbs folder.
#8

[eluser]v1ctoria[/eluser]
It still doesn't work for me, now i guess it's concerning the file and folder rights.
DO you have enables some services in wamp ? nothing related with rights and permissions ?

I'll try to upload it to a web server and see what it changes.
#9

[eluser]d1a8lo24[/eluser]
Not realy except for curl, and 1 or 2 others that i don't think should matter. as far as permissions on this folders they are 0755 and i usually for manipulating the images i also give the same permissions.

You might need to re install or update wamp to the latest.

and yes try a quick test on your live server this will narrow down the problem where either CI or your server setup might be the proble.

By the way, I'm running wamp 64bit on a windows 7 64bit machine.
#10

[eluser]v1ctoria[/eluser]
I've tested the code in my server and seems to do not work.
It is probably a problem with a parameter i have changed.

I will test your code on a new installation tonight.




Theme © iAndrew 2016 - Forum software by © MyBB