开发者

Codeigniter image resize() thumbnail name issue

When I resize an image keeping $config['create_thumb'] = true Codeigniter adds the string "_thumb" in the end of the name of resized image.

What I want ask is, is it possible to add the suffix "_thumb" in the beginning of the image name

example: original_name.jpg

after resizing: original_name_thumb.jpg

What I want: thumb_original_name.jpg

Any开发者_如何学JAVA kind of help is appreciated!


You can try this:

$data = $this->upload->data();
$config['create_thumb'] = false;
$config['new_image'] = 'thumb_'.$data['file_name'];

And if you have other problems with CI image manipulation library, maybe you can try ImageMoo.


If u don't want to add the suffix _thumb in thumbnail file name then use $config['thumb_marker'] = false;


this can be achieved by following way

$data = $this->upload->data();

$config['create_thumb'] = false;

$config['new_image'] = 'thumb_'.$data['file_name'];

for more information about re-size image check out following Code.

function special_resize($oldFile, $width, $height) { $obj =& get_instance();

    $info = pathinfo($oldFile);        
    out($info);

    $tempFile = '/public/files/files/temp/' . $info['filename'] . '-' . $width . 'x' . $height . '.' . $info['extension'];
    $newFile = '/public/files/files/cache/' . $info['filename'] . '-' . $width . 'x' . $height . '.' . $info['extension'];

    //if image already exists, use it
    if(file_exists('.' .$newFile))
        return $newFile;

    //math for resize/crop without loss
    $o_size = _get_size( '/' . $info['dirname'] . '/' . $info['basename']);        

    $master_dim = ($o_size['width']-$width < $o_size['height']-$height?'width':'height');

    $perc = max( (100*$width)/$o_size['width'] , (100*$height)/$o_size['height']  );

    $perc = round($perc, 0);

    $w_d = round(($perc*$o_size['width'])/100, 0);        
    $h_d = round(($perc*$o_size['height'])/100, 0);

            // end math stuff

    /*
     *    Resize image
     */
    $config['image_library'] = 'gd2';
    $config['source_image'] = $oldFile;
    $config['new_image'] = '.' . $tempFile;
    $config['maintain_ratio'] = TRUE;
    $config['master_dim'] = $master_dim;
    $config['width'] = $w_d + 1;
    $config['height'] = $h_d + 1;

    $obj->image_lib->initialize($config);

    $obj->image_lib->resize();

    $size = _get_size($tempFile);    

    unset($config); // clear $config

    /*
     *    Crop image  in weight, height
     */

    $config['image_library'] = 'gd2';
    $config['source_image'] = '.' . $tempFile;
    $config['new_image'] = '.' . $newFile;
    $config['maintain_ratio'] = FALSE;
    $config['width'] = $width;
    $config['height'] = $height;
    $config['y_axis'] = round(($size['height'] - $height) / 2);
    $config['x_axis'] = 0;

    $obj->image_lib->clear();
    $obj->image_lib->initialize($config);
    if ( ! $obj->image_lib->crop())
    {
        echo $obj->image_lib->display_errors();
    }

    $info = pathinfo($newFile);        
    out($info);

    return $newFile;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜