Giter VIP home page Giter VIP logo

js-image-base64's Introduction

简介

JS前端上传图片、压缩、并且处理旋转问题,生成base64数据

演示地址

http://www.tkc8.com/test/pic/index.html

示例代码


<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>image-test</title>
    <meta charset="utf-8"/>
    <script src="base64image.js" type="text/javascript"></script>
    <script src="exif.js" type="text/javascript"></script>	
</head>
<body>
    <input type="file" style="display: none" onchange="fileUp(this)" id="file-up">
    <input type="button" value="点我上传图片" onclick="document.getElementById('file-up').click();"/>
    <div id='image-list'></div>

    <script>
        var fileUp = function (me) {
            base64Image({
                width:750,                             /*【选填】宽度默认750,如果图片尺寸大于该宽度,图片将被设置为该宽度*/
                ratio:0.75,                            /*【选填】压缩率默认0.75 */
                file: me,                              /*【必填】对应的上传元素 */
                callback: function (imageUrl) {        /*【必填】处理成功后的回调函数 */
                    /*imageUrl为得到的图片base64数据,这里可以进行上传到服务器或者其他逻辑操作 */
                    var img = new Image();
                    img.src = imageUrl;
                    $("#image-list").append(img);
                },
            });
        };
    </script>
</body>
</html>

交流方式

联系我们

QQ群: 298420174

图片名称

作者: Sponge 邮箱: [email protected]

js-image-base64's People

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.