当我调整图像大小时保持$config['create_thumb'] = true
Codeigniter在调整大小的图像名称的末尾添加字符串“_thumb”。
我想问的是,是否可以在图像名称的开头添加后缀“_thumb”
例如: original_name.jpg
调整大小后: original_name_thumb.jpg
我想要的: thumb_original_name.jpg
感谢任何形式的帮助!
答案 0 :(得分:10)
你可以试试这个:
$data = $this->upload->data();
$config['create_thumb'] = false;
$config['new_image'] = 'thumb_'.$data['file_name'];
如果你对CI图像处理库有其他问题,也许你可以试试ImageMoo。
答案 1 :(得分:9)
如果您不想在缩略图文件名中添加后缀_thumb,那么
使用$config['thumb_marker'] = false;
答案 2 :(得分:-1)
这可以通过以下方式实现
$ data = $ this-> upload-> data();
$ config ['create_thumb'] = false;
$ config ['new_image'] ='thumb _'。$ data ['file_name'];
有关重新调整大小图片的详细信息,请参阅代码。
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; }