生成缩略图的问题

浏览:261 发布日期:2017/04/21 分类:求助交流 关键字: 缩略图
class Demo extends Controller
{
protected $case_model;
protected $company_model;
protected function _initialize()
{
parent::_initialize();
$this->case_model = new CasesModel();
$this->company_model = new CompanyModel();
}
public function index($index=0,$p=1)
{
//die;
if ($p==2500) {
die;
}
$start = ($p-1)*5;
$data = $this->case_model->limit($start,5)->order('id asc')->select();
//print_r($data);die;
$dir = 'small/';
$pic='';
if ($data)
{
foreach ($data as $key=>$value)
{
$value['content_pic_box'] = unserialize($value['content_pic_box']);

//print_r($value['content_pic_box']);die;

$pic = $value['content_pic_box'][0];

if ($pic!='')
{
$imgname = substr($pic,22);
$imgname_small='244_183_'.$imgname;
echo '本次案例--------- ' . $data[$key]['title'] . ' --------' .$start . '</br>';
echo '本次案例id....' . $data[$key]['id'].'<br>';
echo '要生成缩略图的图片---->'.$imgname.'<br>';
//print_r($imgname);die;
if ($this->smallimg($pic,$dir,$imgname_small)==1)
{
echo '生成缩略图片....' . $imgname_small.'<br>';
echo 'p....' . $p.'<br>';
echo '<br>';
echo '<script>window.scrollTo(0,document.body.scrollHeight+100);</script>';
}else{
break;
}
}
}
}
return $this->success('...ok....',url('Demo/index',array('p'=>$p+1)),1,1);

//return $this->fetch('demo',['data'=>$data]);
}//function--end;

//生成缩略图
function smallimg($obj,$dir,$imgname)
{
$image = img::open($obj);
if ($image){
$image->thumb(244,183)->save($dir.'244_183_'."$imgname");
}else{
return false;
}
return true;

}
最佳答案
评论( 相关
后面还有条评论,点击查看>>