• jQuery imgAreaSelect Examples


    案例:前端图片截取功能

    分布说明A:选择File本地选择的图片 B:根据需求按比例缩放图片 C:区域选择型操作

    A: 选择图片

    <input class="upfile" type="file" id="pictureUpload" name="pictureUpload">
    <image id="SelectImage">

     B: 如果选择的图片比较大,则按照需求缩放即可 

    function AutoResizeImage(TargetWidth, TargetHeight) {
            var img = document.getElementById("SelectImage");
            var IntWidth; 
            var IntHeight; 
            if (img.width > TargetWidth && img.height <= TargetHeight) {
                IntWidth = TargetWidth;
                IntHeight = (IntWidth * img.height) / img.width;
            }
            else if (img.width <= TargetWidth && img.height > TargetHeight) {
                IntHeight = TargetHeight;
                IntWidth = (IntHeight * img.width) / img.height;
            }
            else if (img.Width <= TargetWidth && img.height <= TargetHeight) {
                IntHeight = img.width;
                IntWidth = img.height;
            }
            else {
                IntWidth = TargetWidth;
                IntHeight = (IntWidth * img.height) / img.width;
                if (IntHeight > TargetHeight)
                {
                    IntHeight = TargetHeight;
                    IntWidth = (IntHeight * img.width) / img.height;
                }
            }
            img.height = IntHeight;
            img.width = IntWidth;
        }

     

    C: imgAreaSelect 作用是图片区域选择显示

    例如图示:

     $(document).ready(function () {
    //初始化选择图片区域的裁剪元素
    $('#SelectImage').imgAreaSelect({ aspectRatio: '1:1', handles: true, fadeSpeed: 200, onSelectChange: preview,
       minWidth:100,
       minHeight:100,
    x1: 0, y1: 0, x2: 100, y2: 100 }); });
  • 相关阅读:
    在VMware中使用Nat方式设置静态IP
    saltstack实现自动化扩容
    saltstack常用模块
    saltstack之nginx、php的配置
    桶排序
    【前端安全】JavaScript防http劫持与XSS
    memcached
    10 行 Python 代码写的模糊查询
    为什么print在python3中变成了函数?
    一行python代码实现树结构
  • 原文地址:https://www.cnblogs.com/sfwl_1026/p/5268890.html
Copyright © 2020-2023  润新知