Roz*_*lns 2 codeigniter thumbnails
目前,我正在学习和尝试CodeIgniter能够做到的事情.但我立刻坚持制作多个缩略图.也许,我使用Wordpress搞砸了太多脑袋,并试图在Codeigniter中做这样的事情,但无论如何,这是我的代码
<?php
class Gallery_model extends CI_Model {
var $gallery_path;
function __construct() {
parent::__construct();
$this->load->helper('functions');
$this->gallery_path = realpath(APPPATH . '../uploads');
}
function do_upload() {
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png',
'upload_path' => $this->gallery_path,
'max_size' => 2000
);
$this->load->library('upload', $config);
$this->upload->do_upload();
$image_data = $this->upload->data();
$image_sizes = array(
'thumb' => array(150, 100),
'medium' => array(300, 300),
'large' => array(800, 600)
);
foreach ($image_sizes as $resize) {
$config = array(
'source_image' => $image_data['full_path'],
'new_image' => $this->gallery_path . '-' . $resize[0] . 'x' . $resize[1],
'maintain_ration' => true,
'width' => $resize[0],
'height' => $resize[1]
);
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
}
}
Run Code Online (Sandbox Code Playgroud)
目前,我能够自己创建一个图像,但我不能用这个缩略图.也许有人可以增强代码,让它工作:)
PS - 我试过把$ image_sizes之后的所有内容,把它放在其他独立的php文件中,运行它,并将var转储到foreach里面的$ config,它似乎正在工作.
Yan*_*erk 12
像这样使用它:
$this->load->library('image_lib');
foreach ($image_sizes as $resize) {
$config = array(
'source_image' => $image_data['full_path'],
'new_image' => $this->gallery_path . '-' . $resize[0] . 'x' . $resize[1],
'maintain_ration' => true,
'width' => $resize[0],
'height' => $resize[1]
);
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
}
Run Code Online (Sandbox Code Playgroud)
initialize比使用$config.加载库更好.
| 归档时间: |
|
| 查看次数: |
3446 次 |
| 最近记录: |