1

I searched a lot but can't find out a solution for this problem actually I am trying to resize a image using codeigniter img_library. For resizing I am using this code. I am converting a base 64 encoded image using this code

$imgdata=base64_decode($image);
$imagename=$t.$s.'.'.$type;
$url= $target_dir.$imagename;
file_put_contents($url,$imgdata);         
$this->do_resize($url,$imagename);//calling the function to resize 



public function do_resize($url,$imagename){
   
    $source_path = $url;
    $target_path = base_url(). '/assets/test_images/'.$imagename;
    $config_manip = array(
        'image_library' => 'gd2',
        'source_image' => $source_path,
        'new_image' => $target_path,
        'maintain_ratio' => TRUE,
        'create_thumb' => TRUE,
        'thumb_marker' => '_thumb',
        'width' => 150,
        'height' => 150
    );
   
    $this->load->library('image_lib',$config_manip);
      $this->image_lib->initialize($config_manip);
     
      echo $this->image_lib->display_errors();
    if (!$this->image_lib->resize()) {
        echo $this->image_lib->display_errors();
    }
   
    $this->image_lib->clear();
}

and the error I am getting is this

Severity: Warning

Message: imagecreatefrompng(): gd-png: fatal libpng error: [1E][36][BB][37]: invalid chunk type

Filename: libraries/Image_lib.php

Line Number: 1463 A PHP Error was encountered

Severity: Warning

Message: imagecreatefrompng(): gd-png error: setjmp returns error condition

Filename: libraries/Image_lib.php

Line Number: 1463 A PHP Error was encountered

Severity: Warning

Message: imagecreatefrompng(): 'C:/xampps/htdocs/yallaexab/assets/images/14747161693.jpg' is not a valid PNG file

Filename: libraries/Image_lib.php

Line Number: 1463

5
  • 1
    imagecreatefrompng()... It looks as though it is expecting a PNG file and you gave it a JPEG. Is jpeg image type allowed in the configuration? It normally works it out by looking at the file extension and the first few bytes of the image file. Commented Sep 24, 2016 at 13:09
  • i check the file type using $f = finfo_open(); $mime_type = finfo_buffer($f, $imgdata, FILEINFO_MIME_TYPE); and its giving image/png so file is a valid png file. Commented Sep 24, 2016 at 13:19
  • i tried doing that also but still getting the same error..Message: imagecreatefrompng(): 'C:/xampps/htdocs/yallaexab/assets/images/1474723559188.png' is not a valid PNG file Commented Sep 24, 2016 at 13:26
  • i have check it and its showing there that's y i am saying its not a corrupted file..I think there is some mistake i have made in resize function which i am not able to find out. Commented Sep 24, 2016 at 13:44
  • maybe interesting? stackoverflow.com/questions/19218247/codeigniter-image-resize Commented Sep 24, 2016 at 13:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.