dongsong4418 2013-07-10 07:04
浏览 15
已采纳

允许用户在图像上编写自定义文本

So what i want to do is to have my users write something in a text field and whatever they write there goes on the image so it becomes part of the image, and they can save it to their computer.

I'm going to use a field like this

<input type='text' id='Text' name='Text' maxlength="10">
  • 写回答

3条回答

  • dongzhang7382 2013-07-10 07:24
    关注

    this full example let's you

    1.write the text you want

    2.add an image

    (FileReader,Canvas)needs modern browsers

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title></title>
    <script>
    var
    maxSize=600, // Max width or height of the image
    font='italic small-caps bold 40px/50px arial', // font style
    fontColor='white', // font color
    textX=50, // text x position
    textY=50, // text y position
    h=function(e){
     var fr=new FileReader();
     fr.onload=function(e){
      var img=new Image();
      img.onload=function(){
       var r=maxSize/Math.max(this.width,this.height),
       w=Math.round(this.width*r),
       h=Math.round(this.height*r),
       c=document.createElement("canvas"),cc=c.getContext("2d");
       c.width=w;c.height=h;
       cc.drawImage(this,0,0,w,h);
    
       cc.font=font;
       cc.fillStyle=fontColor;
       cc.fillText(document.getElementById('t').value,textX,textY);
    
       this.src=c.toDataURL();
       document.body.appendChild(this);
      }
      img.src=e.target.result;
     }
     fr.readAsDataURL(e.target.files[0]);
    }
    window.onload=function(){
     document.getElementById('f').addEventListener('change',h,false);
    }
    </script>
    </head>
    <body>
    1.write text
    <input type="text" id="t">
    2.add image
    <input type="file" id="f">
    </body>
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP