Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8740227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:05:39+00:00 2026-06-13T11:05:39+00:00

I’m having trouble trying to resize an image and then create a thumb. Both

  • 0

I’m having trouble trying to resize an image and then create a thumb.

Both functions are working separately but when trying to call them both, only the first call works. No Thumb is created, why ?

Here is my controller:

if($this->upload->do_upload()){

                // Si oui, tout va bien

                //Update DB
                $pictureData = $this->upload->data();
                if($pictureData['file_name']!=''){
                    //On resize l'immage
                        //On charge la librarie
                        $this->load->library('thumbs');

                        $this->thumbs->resize($pictureData['full_path'], 300, 600);

                    $News['image']=$pictureData['file_name'];

                    //On crée un Thumbnail:
                        // on envoi le full path
                        if($this->thumbs->create($pictureData['full_path']))

                        // on stock le path recu
                    $News['thumb'] = $pictureData['raw_name'].'_thumb'.$pictureData['file_ext'];
                }
            }

And here is the library I’ve created for both functions:

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

class Thumbs
{

    function __construct()
    {
        $CI =& get_instance();
        $this->load->library('image_lib');
    }

    public function create($picPath) {

        $CI =& get_instance();

        $config['image_library'] = 'gd2';
        $config['source_image'] = $picPath;
        $config['maintain_ratio'] = TRUE;
        $config['create_thumb'] = TRUE;
        $config['width']     = 100;
        $config['height']   = 100;

        $CI->image_lib->clear();
        $CI->image_lib->initialize($config); 

        if(!$CI->image_lib->resize()){
            $CI->session->set_flashdata('flashError',  $CI->image_lib->display_errors());
            return False;
        }
        $CI->image_lib->clear();
        Return True;

    }

    public function resize($picPath, $x, $y) {

        $CI =& get_instance();

        $config1['image_library'] = 'gd2';
        $config1['source_image']    = $picPath;
        $config1['maintain_ratio'] = TRUE;

        if($x!=0)
            $config1['width']    = $x;

        if($y!=0)
            $config1['height']  = $y;

        $CI->image_lib->clear();
        $CI->image_lib->initialize($config1); 

        if(!$CI->image_lib->resize()){
            $CI->session->set_flashdata('flashError',  $CI->image_lib->display_errors());
            return False;
        }
        $CI->image_lib->clear();
        Return True;
    }
}

So if I call only one, it works fine, wether it is the create or resize function. Otherwise, if I try to call them both, only the first function that has been called works.

EDIT: Thanks to fccotech, I made it. here is the solution he came with:

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

class Thumbs
{

    function __construct()
    {
        $this->CI =& get_instance();
        $this->CI->load->library('image_lib');
    }

    public function create($picPath, $picName) {

        $config =array();

        $config['image_library'] = 'gd2';
        $config['source_image'] = $picPath;
        $config['maintain_ratio'] = TRUE;
        $config['create_thumb'] = TRUE;
        $config['width']     = 100;
        $config['height']   = 100;
        $config['new_image'] =  $picName;

        // $CI->image_lib->clear();
        $this->CI->image_lib->initialize($config); 

        if(!$this->CI->image_lib->resize()){
            $this->CI->session->set_flashdata('flashError',  $this->CI->image_lib->display_errors());
            return False;
        }
        $this->CI->image_lib->clear();
        Return True;

    }

    public function resize($picPath, $x, $y) {

        $config1 = Array();

        $config1['image_library'] = 'gd2';
        $config1['source_image']    = $picPath;
        $config1['maintain_ratio'] = TRUE;

        if($x!=0)
            $config1['width']    = $x;

        if($y!=0)
            $config1['height']  = $y;

        // $CI->image_lib->clear();
        $this->CI->image_lib->initialize($config1); 

        if(!$this->CI->image_lib->resize()){
            $this->CI->session->set_flashdata('flashError',  $this->CI->image_lib->display_errors());
            $this->CI->image_lib->clear();
            return False;
        }
        $this->CI->image_lib->clear();
        Return True;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:05:40+00:00Added an answer on June 13, 2026 at 11:05 am

    After resize add

    $this->image_lib->clear();
    

    So also clear before you do a new $CI->image_lib->initialize($config);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.