Welcome Guest, Not a member yet? Register   Sign In
Question with image_lib
#1

[eluser]AtomicNicholas[/eluser]
Hi, Not sure if I should report this as a bug or it's just my particular system, but I've tried it on Firefox on a Mac and on IE in Parallels:

I've created a basic image uploading setup, much like the example in the user guide but which displays the image that was uploaded together with a thumbnailed version below it.

It works fine for the most part, but intermittently, the browser chokes (in Safari) or gives and outright error in Firefox:

Quote:A PHP Error was encountered

Severity: Warning

Message: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: 7 extraneous bytes before marker 0xd9

Filename: libraries/Image_lib.php

Line Number: 1140

A similar warning is shown below it:

Quote:Message: imagecreatefromjpeg() [function.imagecreatefromjpeg]: '/path/to/my/codeigniter/installation/uploads/THEFILE_01.JPG' is not a valid JPEG file

This is likely with GD / GD2, but it does this randomly regardless of what JPG image I use, and the JPG images are all fine, since the image opens fine and the upload is always successful. I also noticed that sometimes, the thumbnail isn't shown when this error occurs. In Safari the browser just chokes midway, though pressing the upload button a second time fixes it immediately. This occurs randomly, and like 10%-20% of the time.

Secondly, the thumbnails also sometimes goes off-color.

Any ideas? Thanks!
#2

[eluser]Michael Wales[/eluser]
What's your code? I'm using the Image Lib (GD2) for the exact same thing and haven't had any issues on WinXP with IE, Firefox, or Flock.
#3

[eluser]AtomicNicholas[/eluser]
The controller's just based on the user guide (adding to a project but testing it first), and just adding the thumbnailing and immediate display:
Code:
<?

class Upload extends Controller {

    function __construct() {
        parent::Controller();
        $this->load->helper(array('form','url'));

    }
    
    function index() {
        $this->load->view('upload_form', array('error' => ''));

    }
    
    function do_upload() {
    
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '100';
        $config['max_width'] = '1024';
        $config['max_height'] = '768';
        $config['overwrite'] = TRUE;
        // $config['encrypt_name'] = TRUE;     // doesn't work (to check)
        
        $this->load->library('upload');
        $this->upload->initialize($config);
        
        if(!$this->upload->do_upload()) {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('upload_form',$error);
            
        } else {
        
            $data = array('upload_data' => $this->upload->data());

            // test only : create thumbnail
            
            $config['image_library'] = 'GD2';
            $config['source_image']    = $config['upload_path'] . $data['upload_data']['orig_name'];
            $config['create_thumb'] = TRUE;
            $config['maintain_ratio'] = TRUE;
            $config['width'] = 150;
            $config['height'] = 150;
            $config['quality'] = '100%';
            
            // test only: display uploaded image and thumbnail (via the view)
            
            $this->load->library('image_lib', $config);
            
            $data['upload_data']['thumb_width'] = $config['width'];
            $data['upload_data']['thumb_height'] = $config['height'];
        
            $this->load->view('upload_success', $data);

        }
    }
}

?>

What bakes my noodle is because most times it works fine and this warning/error randomly occurs, and even after it happens, the upload is successful in that the image is in the uploaded folder, and re-uploading it may or may not generate the error again.

I'll test it more on a native winXP machine after the weekend, but thus far seems awfully weird.

Many thanks for the help, even if only to check it out.
#4

[eluser]Chris Newton[/eluser]
1. Does the name of the file make any difference?

2. Does it matter whether or not the JPG is saved as a standard vs. progressive JPG.

3. Does the extension matter?




Theme © iAndrew 2016 - Forum software by © MyBB