如何在导出后从src获取base 64 image url(单击按钮)

时间:2017-03-15 14:08:49

标签: javascript jquery html image

我正在为html的图像编辑器工作。目前我的一切都很好,但问题是我想获取导出的编辑图片的网址,以便我可以将其保存到数据库。但问题是我失败了如何得到这个,因为网址没有给出完整的基础64。

这是我的插图:

  1. 我浏览图片
  2. 然后在选择上传的图片后,将图片复制并执行编辑
  3. 导出表示保存图片(在图片编辑器后面打印)
  4. 了解更多信息,请参阅图片:

    enter image description here

    我的调试:

    使用: alert($('#image_data').val());给了我一些东西,当我在浏览器中复制该URL时,它打印如下:

    enter image description here

    警告后,其网址如下:

    data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQwAAACrCAYAAACT4qJxAAAgAElEQVR4nOy9d3yU9ba3nX12t20LiggiNaGXACH03ot0bLS9Vey91y1gRUXFthVFxYIivZOQSupkeu+995JJA673j2FugUNxP+c957zP5/WP7yeZydyTab/rXuu71vpNTjwe5zf9pt/0m36Ncv63H8Bv+k2/6f8e/QaM3/SbftOv1m/A+E2/6Tf9av0GjN/0m37Tr1ZO1O0i4nLiM5mwqVT4DAa8ej1urRaXRoNXqyNoNBGz2Um4XKQ8HoJWKwGLhZjLRczlImSzEXLYSfp9hN1OYj4PyaCfpmiYdDxCOh6hMRYmFQ3RFM6oORKmJRqhLR7jeCLOiWSCE8kErbGooLZ4TPh7Vs2hECST0NwMySQpn4+4201rJAItLRyPxS6oE8kEtDQT87jheBsnU0lSAT9t8Ri0tZIK+GmOhDO3SzdyMpXkeCJOWzxGaywK6UZoTNEWj9EcCWeOSzdCUxrSjcLzOP2YlmiElmiE5kj4jOdyLp3+/M+l7GtyMZ1+TPb/t0QjpENBQY3BgKBUwE8q4Cfp911Q2dudfduEz0vC5yXu9RD3eoh53MQ8bqJu139SxOUUFHY6BIUcdvxWC0G7jbDTIdwme73PZCJoNhM0mvDrDfh0egIGIyGTOfP5dDhpdHtodHtIOl0kHE5iNjsRi5Ww2ULYbCFqurAiRvMFFTZYLqiY2X5BXez/hw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dy8Wz5rJsoULuGXuHCGVOZ6IC5HGiWSCLz/cyOSRI5g+dgzdrm9PfVmp0AKf9SdoTBF2OvBbLajq6+ja/jrqSktoDAbwmIxCh+/qZXfQ5bprye+Vx+j8wYwYOIDrr7ickYMG8uLjj3Fk105cBj0Bm5W60hL+teHdzOCj2cQLjz2KvKYaybFK7FoNdq2GiMvJwhnTGZyXy4iBA7jukktwaTLlUV1tHV6tDk11DY//407scgUhk5m43cF3H33M8LxejOzTl8tycti75VuCRlOmuiJX4lNrSVjt1Ow7QO411zKwU2fG9OlH5a49pOxOwQSNGM04pHKSNgdJm4N933zD5Tk5/PzZp7T5vTy6Yhk3XvpXRvfpRadL/sLbzz1DxGQgajaSsFlI2q0k7VbiVrPgDzx4+1JG9e7J7TOm0P2qy1FVlGCqr+ZE0HsGLMJGLUG9GpdCQsigIaBToSgrZnSfXswdPZIJA/szpm9v/Fo1jU67AKRsRaXRacchk+BVK/n+ww/oftXf2L/la3waFS
    

    但在浏览器控制台上,我看到完全不同:

    <input name="image_data" id="image_data" value="data:image/png;...........
    

    见图: enter image description here

    我不知道为什么我的alert(...)与控制台中显示的<!DOCTYPE html> <html> <head> <title> Exemple de HTML </title> </head> <link rel="stylesheet" type="text/css" href="http://xfer.cybusservices.com/hititpro/assets/vendor/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="http://xfer.cybusservices.com/hititpro/assets/styles/css/annotate.css"> <body> <input type="hidden" name="image_data" id="image_data"> <button class="export-image">Export image</button> <input type="file" id="i_file" value=""> <img onclick="new_image();" src="" width="200" style="display:none;" /> <div style="margin-top:50px"> <div id="myCanvas" style="position:relative"></div> </div> <script type="text/javascript" src="http://xfer.cybusservices.com/hititpro/assets/vendor/js/jquery.min.js"></script> <script type="text/javascript" src="http://xfer.cybusservices.com/hititpro/assets/vendor/js/bootstrap.min.js"></script> <script type="text/javascript" src="http://xfer.cybusservices.com/hititpro/assets/scripts/djaodjin-annotate.js"></script> <script> function new_image(){ var iam=$('#image_data').val(); var counter = 0; $('#myCanvas').on("annotate-image-added", function(event, id, path){ $(".my-image-selector").append("<label><input type=\"radio\" name=\"image-selector\" class=\"annotate-image-select\" value=\"" + path + "\" checked id=\"" + id + "\"><img src=\"" + path + "\" width=\"35\" height=\"35\"></label>"); }); $('#myCanvas').annotate({ color: 'blue', bootstrap: true, images: [iam], onExport: function(image){ if ($("#exported-image").length > 0){ $("#exported-image").remove(); } $("body").append("<img src=\"" + image + "\" id=\"exported-image\">"); } }); $(".export-image").click(function(event) { $('#myCanvas').annotate("export", {type: "http://xfer.cybusservices.com/hititpro/assets/images/jpeg", quality: 0.5},function(d){ $('#image_data').val(d); alert($('#image_data').val()); //not printing complete // alert($('#exported-image').val()); //undefine // console.log(d); }); }); } $('#i_file').change( function(event) { var tmppath = URL.createObjectURL(event.target.files[0]); $('#image_data').val(tmppath); $("img").fadeIn("fast").attr('src',URL.createObjectURL(event.target.files[0])); }); </script> </body> </html> <script> /*var image_data=$('#image_data').val(); if(image_date !=''){ alert(image_data); }*/ </script> 不同。 但是当我复制该值并将其粘贴到浏览器中时,它会显示所有已编辑的图片。

    这是我的代码:

    subscribe

    更新 看到giff我在浏览器中放置的图片链接是否正确打印:

    http://giphy.com/gifs/3oKIP8Aaur7ZsXy5kQ

    注意:我使用的是firefox

    很抱歉,但我必须这样做....请帮助

2 个答案:

答案 0 :(得分:0)

我猜你的代码工作正常。刚刚更新了导出功能并在img标记中加载了基础64数据。哪个工作正常。还要将您的脚本放在document.ready

如果您有任何疑问,请与我们联系。

此外,如果您担心为什么在URL中打开时警报数据看起来不正常,因为alert也有字符限制。因此数据被截断。 https://stackoverflow.com/a/6864674/3008050

        $(function(){
            $('#i_file').change( function(event) {
                var tmppath = URL.createObjectURL(event.target.files[0]);
                $('#image_data').val(tmppath);
                $("img").fadeIn("fast").attr('src',URL.createObjectURL(event.target.files[0]));
             });
            
            $('#img1').click(function(){
                new_image();
            });

            function new_image(){
                var iam=$('#image_data').val();
                var counter = 0;
                $('#myCanvas').on("annotate-image-added", function(event, id, path){
                    $(".my-image-selector").append("<label><input type=\"radio\" name=\"image-selector\" class=\"annotate-image-select\" value=\"" + path + "\" checked id=\"" + id + "\"><img src=\"" + path + "\" width=\"35\" height=\"35\"></label>");
                });

                $('#myCanvas').annotate({
                    color: 'blue',
                    bootstrap: true,
                    images: [iam],
                    onExport: function(image){
                        if ($("#exported-image").length > 0){
                            $("#exported-image").remove();
                        }
                        $("body").append("<img src=\"" + image + "\" id=\"exported-image\">");
                    }
                });

                $(".export-image").click(function(event) {
                    $('#myCanvas').annotate("export", {type: "http://xfer.cybusservices.com/hititpro/assets/images/jpeg", quality: 0.5},function(d){
                        //console.log(d);
                        $('#img2').attr('src',d).fadeIn();
                    });
                });
            }
        });
         
<link href="http://xfer.cybusservices.com/hititpro/assets/vendor/css/bootstrap.min.css" rel="stylesheet"/>
<link rel="stylesheet" type="text/css" href="http://xfer.cybusservices.com/hititpro/assets/styles/css/annotate.css">

<input type="hidden" name="image_data" id="image_data">

<button class="export-image">Export image</button>  
<input type="file" id="i_file" value=""> 
<img src="" id="img1" width="200" style="display:none;" />
<img src="" id="img2" width="200" style="display:none;" />

<div style="margin-top:50px">
    <div id="myCanvas" style="position:relative"></div>
</div>

<script type="text/javascript" src="http://xfer.cybusservices.com/hititpro/assets/vendor/js/jquery.min.js"></script>
    <script type="text/javascript" src="http://xfer.cybusservices.com/hititpro/assets/vendor/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="http://xfer.cybusservices.com/hititpro/assets/scripts/djaodjin-annotate.js"></script>

答案 1 :(得分:0)

使用base64设置图片来源,希望通过这种方式可以帮助您:

How can I set Image source with base64

并且,我尝试使用函数base64EncodeImage()将base64更改为PHP中的图像。