other but working

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Instagram English Hindi Post Creator</title>

<link href="https://fonts.googleapis.com/css2?family=Laila:wght@400;600&family=Baloo+2:wght@400;600&display=swap" rel="stylesheet">

<style>
body{
  margin:0;
  padding:10px;
  background:#eee;
  font-family:'Baloo 2', cursive;
}
.container{
  max-width:420px;
  margin:auto;
  background:#fff;
  padding:12px;
  border-radius:12px;
}
textarea{
  width:100%;
  height:80px;
  margin-bottom:8px;
  padding:8px;
  font-size:16px;
}
.controls{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:8px;
  margin-bottom:10px;
}
button{
  padding:10px;
  font-size:15px;
  border:none;
  border-radius:8px;
  background:#000;
  color:#fff;
  cursor:pointer;
}
canvas{
  width:100%;
  max-width:360px;
  display:block;
  margin:auto;
}
</style>
</head>

<body>

<div class="container">

<textarea id="engText" placeholder="English sentence"></textarea>
<textarea id="hinText" placeholder="हिंदी वाक्य"></textarea>

<div class="controls">
<label>English Color <input type="color" id="engColor" value="#000000"></label>
<label>Hindi Color <input type="color" id="hinColor" value="#000000"></label>

<label>Solid BG <input type="color" id="bgColor" value="#ffffff"></label>
<button onclick="randomGradient()">Random Gradient</button>

<select id="borderStyle">
<option value="solid">Solid Border</option>
<option value="dashed">Dashed Border</option>
<option value="dotted">Dotted Border</option>
</select>

<select id="shape">
<option value="square">Square</option>
<option value="round">Rounded</option>
</select>
</div>

<button onclick="createPost()">Create Image</button>
<button onclick="download()">Download HD</button>

<canvas id="canvas" width="1080" height="1080"></canvas>

</div>

<script>
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");

let currentGradient = null;

function randomGradient(){
  const r = () => Math.floor(Math.random()*256);
  currentGradient = ctx.createLinearGradient(0,0,1080,1080);
  currentGradient.addColorStop(0,`rgb(${r()},${r()},${r()})`);
  currentGradient.addColorStop(1,`rgb(${r()},${r()},${r()})`);
  createPost();
}

function wrapAndFit(text, x, y, width, height, color){
  let size = 90;
  ctx.textAlign="center";
  ctx.textBaseline="middle";

  while(size>10){
    ctx.font = size+"px Laila";
    let words = text.split(" ");
    let lines=[];
    let line="";

    for(let w of words){
      let test=line+w+" ";
      if(ctx.measureText(test).width>width){
        lines.push(line);
        line=w+" ";
      } else {
        line=test;
      }
    }
    lines.push(line);

    let totalHeight = lines.length * size * 1.2;
    if(totalHeight <= height){
      ctx.fillStyle=color;
      let startY = y - totalHeight/2 + size/2;
      for(let i=0;i<lines.length;i++){
        ctx.fillText(lines[i], x, startY + i*size*1.2);
      }
      break;
    }
    size--;
  }
}

function createPost(){
  const eng=document.getElementById("engText").value;
  const hin=document.getElementById("hinText").value;
  const engColor=document.getElementById("engColor").value;
  const hinColor=document.getElementById("hinColor").value;
  const bg=document.getElementById("bgColor").value;
  const border=document.getElementById("borderStyle").value;
  const shape=document.getElementById("shape").value;

  if(currentGradient){
    ctx.fillStyle=currentGradient;
  } else {
    ctx.fillStyle=bg;
  }
  ctx.fillRect(0,0,1080,1080);

  wrapAndFit(eng,540,270,900,500,engColor);
  wrapAndFit(hin,540,810,900,500,hinColor);

  ctx.lineWidth=8;
  ctx.setLineDash(border==="dashed"?[20,10]:border==="dotted"?[5,10]:[]);
  ctx.strokeStyle="#000";
  ctx.strokeRect(20,20,1040,1040);

  canvas.style.borderRadius = shape==="round"?"24px":"0";
}

function download(){
  const a=document.createElement("a");
  a.download="insta_post_"+Date.now()+".png";
  a.href=canvas.toDataURL("image/png");
  a.click();
}
</script>

</body>
</html>

इस ब्लॉग से लोकप्रिय पोस्ट

High Level Advance Random English Words

The History of the World – A Simple and Long Article for English Learners

1. The Art of Self-Discipline