Welcome Guest, Not a member yet? Register   Sign In
Image Manipulation Problem
#1

[eluser]Lazos[/eluser]
Hi. I want to create a script that is automatically creates thumbs when a user visits the image manager.
For example let's say you have an image manager in your webs ite but instead of using that you use the FTP manager to upload them. Now if I want to use the image manager to view my images I want this script to resize them for me to thumbs.

My problem now is that this function it takes all the file names, the loop is ok but it does not resize all the images but just the first one... Any help?

Code:
class Imagemanipulation {

    var $config;
    
    var $CI;
    
    function initialize ($path) {
        $path = '../dissertation/images/upload/'.$path;
        $this->CI =& get_instance();
        $this->CI->load->helper('file');
        $this->config['image_library'] = 'gd2';
        $this->config['source_image'] = '';
        $this->config['create_thumb'] = TRUE;
        $this->config['maintain_ratio'] = TRUE;
        $this->config['width'] = 100;
        $this->config['height'] = 75;
        
        $this->generatethumbs($path);
    }
    
    function generatethumbs($path) {
        $images = array();
        $images = get_filenames($path);
        foreach ($images as $value) {
            $img = strtolower($value);
            $extension = strstr($img, '.');
            if ($extension == '.jpg' || $extension == '.png' || $extension == '.gif') {
            $this->config['source_image'] = $path.$value;
            $this->CI->load->library('image_lib', $this->config);
            $this->CI->image_lib->resize();
            }
        }

    }

}

ANSWER:

Code:
<?php

/**
* @author Lazaros Lazarou
* @copyright 10112008
* @email
*/

class Imagemanipulation {

    var $config;
    
    var $CI;
    
    function initialize ($path) {
        $path = '../dissertation/images/upload/'.$path;
        $this->CI =& get_instance();
        $this->CI->load->helper('file');
        $this->config['image_library'] = 'gd2';
        $this->config['source_image'] = '';
        $this->config['create_thumb'] = TRUE;
        $this->config['maintain_ratio'] = TRUE;
        $this->config['width'] = 100;
        $this->config['height'] = 75;
        $this->CI->load->library('image_lib');
        $this->generatethumbs($path);
    }
    
    function generatethumbs($path) {
        $images = array();
        $images = get_filenames($path);
        foreach ($images as $value) {
            $img = strtolower($value);
            $extension = strstr($img, '.');
            if ($extension == '.jpg' || $extension == '.png' || $extension == '.gif') {
            $this->config['source_image'] = $path.$value;
            $this->CI->image_lib->initialize($this->config);
            $this->CI->image_lib->resize();
            if ( ! $this->CI->image_lib->resize())
            {
            echo $this->CI->image_lib->display_errors();
            }
            $this->CI->image_lib->clear();
            }
        }

    }

}
?>




Theme © iAndrew 2016 - Forum software by © MyBB