需求背景
用户工作完成之后需要将工具摆放完整并拍照上传交由审批人员审批,为了避免用户作弊, 不可以选择相册已经存在的图片
主要功能
- 拍照上传
- 添加水印
- 图片压缩
整体思路
joget 文件上传功能内部已经封装完整, 不需要额外操作, 直接通过input type = file , 用户点击submit , joget会自动处理
限制相册功能通过 input 的 accept 属性和 capture 属性来控制
水印功能通过java自带的图像处理对象Graphics2D处理
压缩功能通过类库Thumbnails处理
核心代码
控制选择类型
<input type="file" accept="image/*" capture="camera">
<input type="file" accept="video/*" capture="camcorder">
<input type="file" accept="audio/*" capture="microphone">
accept属性表示接受哪种类型的文件,*代表所有的后缀, 如果指定为某种格式文件则填写为 accept=“image/gif, image/jpeg”;
capture属性表示打开哪种媒体程序,camera 表示相机 , camcorder 表示录录像机,microphone表示 录音机,当然, 在pc上是无效的;
控制在PC端无法选取文件
function getDevice() {
var userAgentInfo = navigator.userAgent;
console.log(userAgentInfo);
var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");
var flag = false;
for (var v &