Php 代码签名器';s图像处理(使用GD库)不';t调整某些JPEG图像的大小
我有一个上传表单,它采用jpg/gif/等图像,我使用它上传一些图像(图像格式为jpg),用于我的网站使用的图库,但不幸的是,它不能很好地用于某些图像(它使所有内容都变黑,并在左上角(0,0)显示调整大小的图像)。Php 代码签名器';s图像处理(使用GD库)不';t调整某些JPEG图像的大小,php,image,codeigniter,image-processing,file-upload,Php,Image,Codeigniter,Image Processing,File Upload,我有一个上传表单,它采用jpg/gif/等图像,我使用它上传一些图像(图像格式为jpg),用于我的网站使用的图库,但不幸的是,它不能很好地用于某些图像(它使所有内容都变黑,并在左上角(0,0)显示调整大小的图像)。 我试着在线调整图像的大小,但没有问题,所以我认为问题不在于图像本身,而是在库/配置中 我的上载和调整图像处理程序代码: function upload() { //check if admin is logged in. if ($this->
我试着在线调整图像的大小,但没有问题,所以我认为问题不在于图像本身,而是在库/配置中 我的上载和调整图像处理程序代码:
function upload() {
//check if admin is logged in.
if ($this->session->userdata('is_logged') == 1) {
//loading the configuration for the upload library.
$config = array();
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '7000';
$config['max_width'] = '6000';
$config['max_height'] = '5000';
$this->load->library('upload', $config);
if (!$this->upload->do_upload()) {
$data['redirect_msg'] = $this->upload->display_errors() . '<br /> go back to ' . anchor('admin/', 'main page');
$this->load->view('redirect', $data);
} else {
//getting the image's information, in order to resize it.
$upload_data = $this->upload->data();
$image_path = $upload_data['full_path'];
/* loading the configuration for the image manuiplation library. */
$config['image_library'] = 'gd';
$config['source_image'] = $image_path;
$config['width'] = '800';
$config['height'] = '600';
$config['maintain_ratio'] = FALSE; //tried setting it to TRUE aswell.
//loading the library
$this->load->library('image_lib', $config);
//starting the resize proccess.
$this->image_lib->resize();
//checking if the is an error in the resizing proccess.
if (!$this->image_lib->resize()) {
/* displaying the errors */
$data['redirect_msg'] = $this->image_lib->display_errors();
$this->load->view('redirect', $data);
} else {
/* show positive message. */
$data['redirect_msg'] = 'Upload successful!<br />redirecting to ' . anchor('admin/', 'homepage') . ' in 3 seconds';
$this->load->view('redirect', $data);
//saving the image name to a database table, so we can retrieve it when needed(for the slideshow).
$this->db_model->save_image($upload_data['orig_name']);
//doing the redirect.
header('refresh:3;url=' . site_url('admin/'));
}
}
} else { //if not logged in, show negative message.
$data['redirect_msg'] = 'you are not logged in. < br/> login ' . anchor('admin/', 'here');
$this->load->view('redirect', $data);
}
}
函数上传(){
//检查管理员是否已登录。
如果($this->session->userdata('is_logged')==1){
//正在加载上载库的配置。
$config=array();
$config['upload_path']='./uploads/';
$config['allowed_types']='gif | jpg | png';
$config['max_size']='7000';
$config['max_width']='6000';
$config['max_height']='5000';
$this->load->library('upload',$config);
如果(!$this->upload->do_upload()){
$data['redirect_msg']=$this->upload->display_errors()。
返回到.anchor('admin/','main page');
$this->load->view('redirect',$data);
}否则{
//获取图像的信息,以便调整其大小。
$upload_data=$this->upload->data();
$image_path=$upload_data['full_path'];
/*正在加载映像制造库的配置*/
$config['image_library']='gd';
$config['source\u image']=$image\u路径;
$config['width']='800';
$config['height']='600';
$config['mainter_ratio']=FALSE;//也尝试将其设置为TRUE。
//加载库
$this->load->library('image_lib',$config);
//正在启动调整大小过程。
$this->image_lib->resize();
//正在检查调整大小过程中是否存在错误。
如果(!$this->image\u lib->resize()){
/*显示错误*/
$data['redirect_msg']=$this->image_lib->display_errors();
$this->load->view('redirect',$data);
}否则{
/*显示积极的信息*/
$data['redirect_msg']='上载成功!
重定向到'.anchor('admin/','homepage')。'在3秒钟内';
$this->load->view('redirect',$data);
//将图像名称保存到数据库表中,以便在需要时检索(用于幻灯片放映)。
$this->db_model->save_image($upload_data['orig_name']);
//执行重定向。
标题('refresh:3;url='。site_url('admin/');
}
}
}否则{//如果未登录,则显示负面消息。
$data['redirect_msg']=“您未登录。
login.anchor('admin/','here');
$this->load->view('redirect',$data);
}
}
您正在两次调整该图像的大小:
//starting the resize proccess.
$this->image_lib->resize();
//checking if the is an error in the resizing proccess.
if (!$this->image_lib->resize()) {
只要做一次:
//starting the resize proccess.
//checking if the is an error in the resizing proccess.
if (!$this->image_lib->resize()) {
你试过图像库gd2吗?@Kokers是的,我试过使用它。同样的结果。