我想仅使用动态宽度创建一张新照片,以便高度随后根据宽度自动更改。
以下代码与我无关。
$w = $width;
$w = $w / 4 ;
$mconfig['width'] = $w;
$mconfig['maintain_ratio'] = TRUE;
$mconfig['source_image'] = 'uploads/watermark.png';
$mconfig['new_image'] = 'uploads/images/watermark/watermark.png';
$this->image_lib->initialize($mconfig);
$this->image_lib->resize();
$this->image_lib->clear();
答案 0 :(得分:0)
尝试设置高度
例如
$config['height'] = 50;
答案 1 :(得分:0)
试试这个:
//Imagine you need Width 1000px
$height = ($fdata["image_height"] * 1000) / $fdata['image_width'];
$resize_height = (int)$height;
$mconfig['width'] = 1000;
$mconfig['height'] = $resize_height;
$mconfig['maintain_ratio'] = TRUE;
$mconfig['source_image'] = 'uploads/watermark.png';
$mconfig['new_image'] = 'uploads/images/watermark/watermark.png';
$this->image_lib->initialize($mconfig);
$this->image_lib->resize();
$this->image_lib->clear();
此处$fdata["image_height"]
已上传图片高度,$fdata['image_width']
已上传图片宽度。
答案 2 :(得分:0)
试试这个,
$uploaded_data = $this->upload->data();
$w = $width / 4;
$config['width'] = $w;
$config['height'] = round($uploaded_data['image_height']/($uploaded_data['image_width']/$w), 2);
$config['image_library'] = 'gd2';
$config['source_image'] = 'uploads/watermark.png';
$config['new_image'] = 'uploads/images/watermark/watermark.png';
$config['quality'] = "100%";
$config['maintain_ratio'] = true;
$this->load->library('image_lib', $config);
$this->image_lib->initialize($config);
if ($this->image_lib->resize()){
$this->image_lib->clear();
return true;
}else{
return $this->image_lib->display_errors();
}