如何在codeigniter中将上传图像比率限制为16:9? [英] How to restrict the upload image ratio to 16:9 in codeigniter?

查看:158
本文介绍了如何在codeigniter中将上传图像比率限制为16:9?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $ this->加载 - >库('上传'); 
$ ext = pathinfo($ file_name,PATHINFO_EXTENSION);

$ img_name = now()。 。 $ EXT;

$ imgConfig ['upload_path'] = $ this-> image_path;
$ imgConfig ['file_name'] = $ img_name;
$ imgConfig ['max_size'] ='2048';
$ imgConfig ['allowed_types'] ='jpg | png | bmp';
$ imgConfig ['overwrite'] = FALSE;
$ this-> upload-> initialize($ imgConfig);

if($ this-> upload-> do_upload(image_url)){
$ this-> Playlist_model-> update_playlist($ insert_id,array(image_url => $ img_name));
}

而前端只是一个

 < input type ='file'> 

问题是,因为图像上传应该是一个视频缩略图,我应该怎么做才能实现上传?例如在前端使用插件来限制/裁剪(任何推荐)

另外,在服务器端,我该如何检查?

解决方案

  maintain_ratio 



它保持你喜欢的偏好比例



 指定在调整大小或使用硬值时是否保持原始高宽比。 

更多详情
https://ellislab.com/codeigniter/user-guide/libraries/image_lib.html
根据宽度调整图像大小&裁剪额外高度,Codeigniter
在Codeigniter中调整大小和裁剪

Here is the code I used for uploading an image.

$this->load->library('upload');
$ext = pathinfo($file_name, PATHINFO_EXTENSION);

$img_name = now() . "." . $ext;

$imgConfig['upload_path'] = $this->image_path;
$imgConfig['file_name'] = $img_name;
$imgConfig['max_size'] = '2048';
$imgConfig['allowed_types'] = 'jpg|png|bmp';
$imgConfig['overwrite'] = FALSE;
$this->upload->initialize($imgConfig);

if ($this->upload->do_upload("image_url")) {
    $this->Playlist_model->update_playlist($insert_id, array("image_url" => $img_name));
}

And the frontend is simply a

<input type = 'file' >

The problem is , as the image upload should be an video thumbnail, what should I do to implement the upload? e.g using plugin in frontend to restrict/ crop (any recommendation)

Also, in server side how can I check?

解决方案

maintain_ratio

it the Preference you to maintain ratio

Specifies whether to maintain the original aspect ratio when resizing or use hard values.

For more details https://ellislab.com/codeigniter/user-guide/libraries/image_lib.html Resize image according to width only & crop Extra Height , Codeigniter Resizing and cropping in Codeigniter

这篇关于如何在codeigniter中将上传图像比率限制为16:9?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆