cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <h2 class="heading">Image Generator</h2>
<div class="button">
      <a href="https://phe0nix.github.io/" id="home" class="button">
        <span>Home</span>
      </a>
      <a href="https://github.com/Phe0nix/anymini" id="view-on-github" class="button">
        <span>View on GitHub</span>
      </a>
    </div>
<p>Width: <input type="text" class="width" placeholder="width without extension"></p>
<p>Height: <input type="text" class="height" placeholder="height without extension"></p>
<p>Background: <input type="color" class="bgColor"></p>
<button class="gen">Generate Image</button>
<p class="result">
  <canvas style="display: none" class="block"></canvas>
</p>
<div class="type_and_download_image" style="display: none">
  <p>Image Format:
    <select name="imageType" id="imageType">
	<option value="" disabled selected>Choose a format</option>
	<option value="png">.png</option>
	<option value="jpeg">.jpg</option>
</select>
    <span class="quality" style="display: none">Jpg Quality: 
    <select id="quality_value">
		<option value="" disabled selected>Choose quality</option>
	<option value="low">Low</option>
	<option value="med">Medium</option>
	<option value="high">High</option>
</select>
</span>
  </p>
  <a href="#" class="download">Download</a>
</div>
            
          
!
            
              body {
  font-family: helvetica;
  font-size: 15px;
	padding: 10px 20px;
	margin: 0;
}

input {
  vertical-align: middle;
}

input[type=text] {
  border: 1px solid lightgrey;
  height: 20px;
  border-radius: 6px;
  padding: 5px 10px;
}

select {
  border: 1px solid lightgrey;
  border-radius: 6px;
  padding: 5px 10px;
}
#imageType{
	margin-bottom: 10px;
}

input[type=text]:focus {
  border: 1px solid #32809a;
  outline: 0;
  height: 20px;
  border-radius: 6px;
  padding: 5px 10px;
}

input[type=color] {
  padding: 0;
  height: 30px;
  background: transparent;
  border: 0;
  box-shadow: none;
  outline: 0;
  width: 60px;
}
input[type=color]:focus {
  border: 1px solid #32809a;
}
.heading {
    text-align: center;
    width: 70%;
    margin-left: auto;
    margin-right: auto;
}
button,
a.download {
  border: 1px solid lightgrey;
  padding: 8px 12px;
  background: linear-gradient(to bottom, white 30%, #e9e9e9 80%);
  cursor: pointer;
	text-decoration: none;
  border-radius: 6px;
  font-size: 15px;
}

button:active,
a.download:active {
  outline: 0;
  background: linear-gradient(to bottom, #e9e9e9 40%, #fff 80%);
}

.result span {
  display: block;
  background: #e04343;
  padding: 12px 13px;
  color: #fff;
  line-height: 1.5;
}
.button{
  text-align: center;
  margin-bottom: 20px;
}
.button a.button {
    display: inline-block;
    padding: 12px 30px;
    margin-right: 14px;
    font-size: 15px;
  text-decoration: none;
    font-weight: bold;
    line-height: 25px;
    color: #303030;
    background: #fdfdfd;
    background: -moz-linear-gradient(top, #fdfdfd 0%, #f2f2f2 100%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #fdfdfd), color-stop(100%, #f2f2f2));
    background: -webkit-linear-gradient(top, #fdfdfd 0%, #f2f2f2 100%);
    background: -o-linear-gradient(top, #fdfdfd 0%, #f2f2f2 100%);
    background: -ms-linear-gradient(top, #fdfdfd 0%, #f2f2f2 100%);
    background: linear-gradient(top, #fdfdfd 0%, #f2f2f2 100%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fdfdfd', endColorstr='#f2f2f2',GradientType=0 );
    border-top: solid 1px #cbcbcb;
    border-right: solid 1px #b7b7b7;
    border-bottom: solid 1px #b3b3b3;
    border-left: solid 1px #b7b7b7;
    border-radius: 30px;
    -webkit-box-shadow: 10px 10px 5px #888;
    -moz-box-shadow: 10px 10px 5px #888;
    box-shadow: 0px 1px 5px #e8e8e8;
    -moz-border-radius: 30px;
    -webkit-border-radius: 30px;
}
#view-on-github span {
    background: transparent url(https://phe0nix.github.io/assets/images/octocat-icon.png) 0 50% no-repeat;
}
#home span {
    background: transparent url(https://avatars0.githubusercontent.com/u/9951055) 1px 50% no-repeat;
  background-size: 20px;
}
a.button span {
    display: block;
    height: 23px;
    padding-left: 35px;
}
@media screen and (max-width: 600px) {
    .heading {
        width: 100%;
        font-size: 22px;
        font-weight: 600;
        margin: 8px auto 5px;
    }
		.button a.button{
    display: inline-block;
    padding: 5px 14px;
    font-size: 13px;
    text-decoration: none;
    font-weight: bold;
    line-height: 25px;
    color: #303030;
    transition: 0.2s linear;
  }
  .button a.button:not(:last-child){
    margin-right: 6px;
  }
  ::-webkit-input-placeholder {
    font-size: 14px;
  }
  ::-moz-placeholder {
    font-size: 14px;
  }
  :-moz-placeholder {
    font-size: 14px;
  }
  :-ms-input-placeholder {
    font-size: 14px;
  }
}

            
          
!
            
              var w = document.querySelector(".width"),
  h = document.querySelector(".height"),
  r = document.querySelector(".result"),
  bg = document.querySelector(".bgColor"),
  block,
  genBtn = document.querySelector(".gen"),
  dl = document.querySelector(".download"),
  canva = document.querySelector(".block"),
  typeAndDownloadImage = document.querySelector(".type_and_download_image"),
  imageType = document.querySelector("#imageType"),
  quality = document.querySelector(".quality"),
  quality_value = document.querySelector("#quality_value"),
  c, url;

function createCanvas() {
  if (w.value === '' || w.value.match(/\s{1,}/)) {
    r.innerHTML = `<span>Please insert width of the image.</span>`;
    w.focus();
    typeAndDownloadImage.style.display = "none";
  } else if (isNaN(w.value)) {
    r.innerHTML = `<span>"${w.value}" is not a correct width value. Try - 45 / 50 / 85. kiddo!!</span>`;
    w.focus();
    typeAndDownloadImage.style.display = "none";
  } else if (h.value === '' || h.value.match(/\s{1,}/)) {
    r.innerHTML = `<span>Please insert height of the image.</span>`;
    h.focus();
    typeAndDownloadImage.style.display = "none";
  } else if (isNaN(h.value)) {
    r.innerHTML = `<span>"${h.value}" is not a correct height value. Try - 45 / 50 / 85. kiddo!!</span>`;
    h.focus();
    typeAndDownloadImage.style.display = "none";
  } else {
    r.innerHTML = "";
    canva.style.display = "block";
    canva.setAttribute("width", parseInt(w.value) + "px");
    canva.setAttribute("height", parseInt(h.value) + "px");
    c = canva.getContext("2d");
    c.fillStyle = bg.value;
    c.fillRect(0, 0, w.value, h.value);
		c.font= w.value/15 + "px Helvetica";
		c.fillStyle = "#fff";
		c.textAlign = "center";
		c.fillText(""+ w.value +"px / "+ h.value +"px", (w.value/2), (h.value/2));
    r.append(canva);
    typeAndDownloadImage.style.display = "block";
    url = canva.toDataURL();
  }
}

imageType.addEventListener("input", function() {
  if (this.value === "png") {
    quality.style.display = "none";
  } else {
    url = canva.toDataURL("image/jpeg");
    quality.style.display = "block";
  }
});

quality_value.addEventListener("input", function() {
  if (this.value === "low") {
    url = canva.toDataURL("image/jpeg", 0.1);
  } else if (this.value === "med") {
    url = canva.toDataURL("image/jpeg", 0.6);
  } else {
    url = canva.toDataURL("image/jpeg", 1.0);
  }
});

function downloadImage() {
  if(url){
		this.setAttribute("href", url);
  this.setAttribute("download", "new-generate-image-kiddo");
	}
	else{
		alert("Please choose a image format first.");
	}

}

genBtn.addEventListener("click", createCanvas);

dl.addEventListener("click", downloadImage);

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console