• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Another image_lib Library Issue (killing me)

#1
[eluser]Unknown[/eluser]
So I'm creating a class to process avatars for my site. The objective is to:

1.) upload the image
2.) resize THAT same image
3.) create a smaller thumbnail of the image
4.) crop THAT same thumbnail in to a 50x50px square

However, my script is failing at step 3.

I've looked at a few similar posts and incorporated what I learned from them with still no luck. Any ideas?

Thanks.

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Avatar_upload {
    
    var $CI;
    var $fileData;
    
    function Avatar_upload()
    {
        $this->CI =& get_instance();
        $this->CI->load->library('upload');
        $this->CI->load->library('image_lib');
        $this->CI->load->library('session');
    }
    
    /* -------------------------- */
    /* via $this->avatar_upload->processAvatar();  */
    /* -------------------------- */
    function processAvatar()
    {
    
        if ($this->uploadFile())
        {
        
            $this->fileData = $this->CI->upload->data();
            
            if ($this->process_image($this->fileData))
            {
                return 'SUCCESS';
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
    
    /* -------------------------- */
    /* Preform Upload */
    /* -------------------------- */
    function uploadFile()
    {
        $config['upload_path'] = ROOT.STORAGE.'/avatars/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['file_name'] = md5($this->CI->session->userdata('username'));
        $config['max_size']    = '9000';
        $config['overwrite']    = TRUE;
        $config['max_width']  = '5000';
        $config['min_height']  = '5000';
        $this->CI->upload->initialize($config);
        return $this->CI->upload->do_upload();
    }
    
    /* -------------------------- */
    /* Resize to Larger & Smaller & Crop */
    /* -------------------------- */
    function process_image($data)
    {
        $config['image_library'] = 'gd2';
        $config['source_image'] = ROOT.STORAGE.'/avatars/'.$data['file_name'];
        $config['maintain_ratio'] = TRUE;
        $config['width'] = 220;
        $config['height'] = 320;
        $this->CI->image_lib->initialize($config);
        if ($this->CI->image_lib->resize())
        {
            $this->CI->image_lib->clear();
            $config['image_library'] = 'gd2';
            $config['source_image'] = ROOT.STORAGE.'/avatars/'.$data['file_name'];
            $config['new_image'] = ROOT.STORAGE.'/avatars/thumb_'.$data['file_name'];
            $config['width'] = 100;
            $config['height'] = 100;
            $config['maintain_ratio'] = TRUE;
            $this->CI->image_lib->initialize($config);
            return $this->CI->image_lib->resize();
            /* -------------------------- */
               /* Crop is next up here */
            /* -------------------------- */
        }
    }
}

#2
[eluser]Aken[/eluser]
It would help a lot if you could narrow down where in your class it is actually failing. For instance, is it not entering the IF statement after the first resize at all, or is the second resize statement itself failing?

#3
[eluser]Unknown[/eluser]
I just now actually found out the issue was permissions with the image file itself. This brings me to a next possible issue which would be setting permissions upon uploading. Do I need to manually set this or was this a possible freak accident that the permissions on the file we're not writable?

#4
[eluser]CroNiX[/eluser]
[quote author="iisthesloth" date="1259377433"]I just now actually found out the issue was permissions with the image file itself. This brings me to a next possible issue which would be setting permissions upon uploading. Do I need to manually set this or was this a possible freak accident that the permissions on the file we're not writable?[/quote]
For uploading, you most likely need to set the directory permission to 777. Then files will be writable in that dir. This is also the case when using a graphics library to do manipulation...the dir needs to be writable for GD (or whatever) to save its processed image.

#5
[eluser]jedd[/eluser]
The name 'iisthesloth' kind of hints at a certain operating system / web server combination, doesn't it.

But, iisthesloth, are you seriously asking about operating system and file system security without saying what operating system and file system you're using? Surely not.

Actually, the fact that you could upload files without setting looser permissions does imply a certain pervasive Microsoft influence to the system.

#6
[eluser]alrightythen[/eluser]
Does anyone have a solution for this problem? I'm kind of facing the same issue.

My photo uploads to the server in a folder I created dynamically like this
Code:
mkdir($dir, 0700, true);

The uploading works, the creating the thumb works.

But now I want to resize the original photo so that it could fit in a fixed box. But it doesn't work.

This is the code in wich i want to resize my original photo.
Code:
$config['image_library'] = 'gd2';
$config['source_image'] = $dir.$file;
$config['maintain_ratio'] = TRUE;
$config['height'] = 475;
$config['width'] = 680;

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

$this->image_lib->initialize($config);
if(!$this->image_lib->resize()) echo $this->image_lib->display_errors('<p>', '</p>');

I've placed echo statements on eachline to test. and I runs every line except the last line. I don't know what i'm doing wrong, I've just copypasted the code from my thumbCreate()

#7
[eluser]alrightythen[/eluser]
ok I've somewhat fixed it. When I change the height and width to 400 it works but my canvas is 475 x 680 how can i resize an image to that size?

#8
[eluser]alrightythen[/eluser]
k nevermind I've increase my memory usage in mamp and it solved the problem. hope this works on my server too.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.