0

I am having a problem while creating image thumbnails in codeigniter. The problem is images are not stored on the same server. It's stored in amazon server and the url is stored in our server. So while processing to get the image thumb from the url it does not show any error, and it's not creating a thumbnail too. I don't know what is wrong with my code. Below is my code for the initialization of the image library. I am passing the image url to the below block of code dynamically.

    $config['image_library'] = 'gd2';
    $config['source_image'] = $imgUrl;
    $config['create_thumb'] = TRUE;
    $config['maintain_ratio'] = TRUE;
    $config['width']    = 75;
    $config['height']   = 50;
    $config['new_image'] = FCPATH."assets/img/";
    $config['thumb_marker'] = '_thumb';
    
    $this->load->library('image_lib', $config); 
    $this->image_lib->resize();

    echo "<pre>";
    print_r($config);
    echo "</pre>";

Below is one sample response from that print.

Array
(
    [image_library] => gd2
    [source_image] => https://ls-test-bucket.s3.amazonaws.com/Uploadedimage/14405666901132976211195505780617677415047103069725429n.jpg
    [create_thumb] => 1
    [maintain_ratio] => 1
    [width] => 75
    [height] => 50
    [new_image] => D:\zend\Apache2\htdocs\CodeIgniter3_1/assets/img/
    [thumb_marker] => _thumb
)

So how can I create a thumbnail from the url in codeigniter? Note: I already have write access to the new image folder.

2
  • 1
    You must first download an image file on your server, save it, and performs all operations with local file. Commented Aug 26, 2015 at 7:29
  • Download the image from given URL, convert it into thumbnail, then you can delete the downloaded image. Commented Aug 26, 2015 at 9:17

1 Answer 1

4
$image= "https://ls-test-bucket.s3.amazonaws.com/Uploadedimage/14405666901132976211195505780617677415047103069725429n.jpg";   
$data = file_get_contents($image);
/*store image in server*/
$new  = "file/path/to/imagename.jpg";
/*Write the contents back to a new file*/
file_put_contents($new, $data);
$config['image_library'] = 'gd2';
$config['source_image'] = $new;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width']    = 75;
$config['height']   = 50;
$config['new_image'] = FCPATH."assets/img/";
$config['thumb_marker'] = '_thumb';
$this->load->library('image_lib', $config); 
$this->image_lib->resize();
Sign up to request clarification or add additional context in comments.

Comments

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.