Welcome Guest, Not a member yet? Register   Sign In
image_lib->crop()
#1

[eluser]AdamCMills[/eluser]
This seems to do nothing ... I am running it here:

http://myvaluecoupons.com/user_panel/avatar_upload

log in
user: test
pass: test!
if you upload an image
drag on the large version to create crop marks (should see a preview of how it should look)
then click the "crop" button, you'll see it seems to do nothing. This is the code I have running:

Code:
$config['image_library'] = 'gd2';
$config['source_image'] = $this->session->flashdata('file');
$config['x_axis'] = $_POST['x'];
$config['y_axis'] = $_POST['y'];
$config['maintain_ratio'] = FALSE;
        
$this->load->library('image_lib', $config);
if ( ! $this->image_lib->crop()){
     echo $this->image_lib->display_errors();
}
echo '<img src="'.substr($config['source_image'],1).'" />';

if I set a height ... it does something just not very much ... any help on how exactly to get this crop to show up, and correctly would be greatly appreciated.
#2

[eluser]Thorpe Obazee[/eluser]
1. you need to save the file on the server
2. the source image is the file on your server, not the cropped file

At least this is what I think. Haven't used the image lib for cropping.
#3

[eluser]AdamCMills[/eluser]
oh whoops, that file isn't going to work without a login ...

login in with these credentials then follow those steps ... sorry

user: test
pass: test!


and $this->session->flashdata('file');

is the file on the server you just uploaded.
#4

[eluser]Thorpe Obazee[/eluser]
[quote author="AdamCMills" date="1244533902"]This seems to do nothing ... I am running it here:

http://myvaluecoupons.com/user_panel/avatar_upload

log in
user: test
pass: test!
if you upload an image
drag on the large version to create crop marks (should see a preview of how it should look)
then click the "crop" button, you'll see it seems to do nothing. This is the code I have running:

Code:
$config['image_library'] = 'gd2';
$config['source_image'] = $this->session->flashdata('file');
$config['x_axis'] = $_POST['x'];
$config['y_axis'] = $_POST['y'];
$config['maintain_ratio'] = FALSE;
        
$this->load->library('image_lib', $config);
if ( ! $this->image_lib->crop()){
     echo $this->image_lib->display_errors();
}
echo '<img src="'.substr($config['source_image'],1).'" />';

if I set a height ... it does something just not very much ... any help on how exactly to get this crop to show up, and correctly would be greatly appreciated.[/quote]

Try using
Code:
$this->load->library('image_lib');
$this->image_lib->initialize($config)
instead of
Code:
$this->load->library('image_lib', $config);
#5

[eluser]AdamCMills[/eluser]
Same results it would seem. Does nothing to the image.
#6

[eluser]Thorpe Obazee[/eluser]
Can you verify that the flashdata return a value?
#7

[eluser]AdamCMills[/eluser]
Verified, using the same variable to redisplay the image "on success".

I can accomplish the resize functionality just fine, just the crop code seems to do nothing. I'm wondering if maybe it was a typo in the documentation?

It does seem to be missing something ... the reason I say this is...

It gets a X axis, it gets a Y axis, but it doesn't get a height and width to base the other two points for a crop off of. I just don't under stand how the code would know unless it assumes you are cropping a specific size.


And it seems this is the case ... inside the image_process_gd function in the Image_lib.php libarary file ... line 448:

line 453:
Code:
// If the target width/height match the source, AND if the new file name is not equal to the old file name
        // we'll simply make a copy of the original with the new name... assuming dynamic rendering is off.
        if ($this->dynamic_output === FALSE)
        {
            if ($this->orig_width == $this->width AND $this->orig_height == $this->height)            
            {
                 if ($this->source_image != $this->new_image)
                 {
                    if (@copy($this->full_src_path, $this->full_dst_path))
                    {
                        @chmod($this->full_dst_path, DIR_WRITE_MODE);
                    }
                }
                
                return TRUE;
            }
        }

So the if statement on line 472 never gets execture because you didn't set a height and width.

RESOLVED:

Despite documentation had to set height and width and the maintain ratio to false ... my workign code looks like this:

Code:
function crop(){
        $config['image_library'] = 'gd2';
        $config['source_image'] = $this->session->flashdata('file');
        $config['x_axis'] = $_POST['x'];
        $config['y_axis'] = $_POST['y'];
        $config['height'] = $_POST['h'];
        $config['width'] = $_POST['w'];
        $config['maintain_ratio'] = FALSE;
        
        $this->load->library('image_lib');
        $this->image_lib->initialize($config);
        if ( ! $this->image_lib->crop())
        {
            echo $this->image_lib->display_errors();
        }
        echo '<img src="'.substr($config['source_image'],1).'" />';
        
        
    }
#8

[eluser]Unknown[/eluser]
oh dude, thanks so much.
i think ci authors should see it and update their docs on the subject.
#9

[eluser]thesf[/eluser]
[quote author="bargainph" date="1244536183"]
Try using
Code:
$this->load->library('image_lib');
$this->image_lib->initialize($config)
instead of
Code:
$this->load->library('image_lib', $config);
[/quote]

Its also worth noting that even with a width and height set it wont work unless you use the above tip. Very annoying!

Though it might work if its your first use of the image library. I was resizing and then cropping and had used
Code:
$this->image_lib->clear();
unset($config);
in between the two but got errors until I started to use the longer version to initialize the config variables. This has got me wondering why it doesnt work with passing the config variables when loading the library?

EDIT: Now I think about it maybe it was because the image library had already been loaded once so loading it again wasn't actually doing anything and therefore not initializing the config variables?




Theme © iAndrew 2016 - Forum software by © MyBB