Welcome Guest, Not a member yet? Register   Sign In
Help understanding image_lib - resizing?!
#7

[eluser]gRoberts[/eluser]
Wink whey. We're onto a winner. Now I have another problem. All my thumbs have the "_thumb" in the filename.

Code:
<?php

    /**
     * @author Gavin Roberts
     * @copyright 2007
     */
    
    class thumbGenerator {
                
        public $imageDir;
        private $base;
                
        public function __construct() {
            
            $this->base =& get_instance();
            $this->base->load->library('image_lib');
            
        }
        
        public function generate($source, $output, $width, $height) {
            
            $config['source_image'] = $source;
            $config['maintain_ratio'] = TRUE;
            $config['create_thumb'] = true;
            $config['new_image'] = $output;
            $config['quality'] = 100;
            $config['width'] = (int)$width;
            $config['height'] = (int)$height;
            
            $this->base->image_lib->initialize($config);
            if(!$this->base->image_lib->resize())
                die($this->base->image_lib->display_errors());
            
            $tempOutput = $this->generateThumbName($output);
            chmod($tempOutput, 0777);
            rename($tempOutput, $output);
            
        }
        
        private function generateThumbName($name) {
            
            $pi = pathinfo($name);
            return dirname($name) . '/' . $pi['filename'] . '_thumb.' . $pi['extension'];
            
        }
        
        public function applyWatermark($to, $watermark) {
            
            $config['source_image'] = $to;
            $config['wm_type'] = 'overlay';
            $config['quality'] = 100;
            $config['wm_overlay_path'] = $watermark;
            $config['wm_opacity'] = 50;
        
            $this->base->image_lib->initialize($config);
            return $this->base->image_lib->watermark();
            
        }
        
    }

?>

Thats my code.

Whats annoying me is that rename is actually creating a copy of the file and not renaming it.

So is there any way to explicitly set the new filename when creating a thumbnail?

Cheers again!


Messages In This Thread
Help understanding image_lib - resizing?! - by El Forum - 12-10-2007, 02:44 PM
Help understanding image_lib - resizing?! - by El Forum - 12-10-2007, 03:10 PM
Help understanding image_lib - resizing?! - by El Forum - 12-11-2007, 01:37 AM
Help understanding image_lib - resizing?! - by El Forum - 12-11-2007, 11:45 AM
Help understanding image_lib - resizing?! - by El Forum - 12-11-2007, 11:57 AM
Help understanding image_lib - resizing?! - by El Forum - 12-11-2007, 12:12 PM
Help understanding image_lib - resizing?! - by El Forum - 12-11-2007, 03:14 PM
Help understanding image_lib - resizing?! - by El Forum - 12-11-2007, 03:17 PM
Help understanding image_lib - resizing?! - by El Forum - 12-11-2007, 03:26 PM



Theme © iAndrew 2016 - Forum software by © MyBB