GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - completejavascript/nine-patch-js: ⛏️ Scale a nine-patch image using JavaScript's canvas.

BranchesTags
Open more actions menu

Latest commit

 

History

17 Commits
17 Commits

Folders and files

NameName
Last commit message
Last commit date
LICENSE
LICENSE
 
 
NinePatch.js
NinePatch.js
 
 
README.md
README.md
 
 
index.html
index.html
 
 
index.js
index.js
 
 
test_normal.9.png
test_normal.9.png
 
 

Repository files navigation

NinePatch.js

Scale nine-patch image using JavaScript's canvas.

Usage

  • APIs:
    • getSize(srcImg) => {url, width, height}: 'url' is the original image's url
    • scaleImage(srcImg, newWidth, newHeight) => url: 'url' is the new image's url, which is scaled.

Example

const srcImg = 'test_normal.9.png';
const WIDTH = 150;
const HEIGHT = 150;

document.addEventListener("DOMContentLoaded", event => {
  let $ = document.querySelector.bind(document);

  new NinePatch().getSize(srcImg)
  .then(result => setImage($('#ninePatchImg'), result.url, result.width, result.height))
  .catch(error => console.log(error));

  new NinePatch().scaleImage(srcImg, WIDTH, HEIGHT)
  .then(result => setImage($('#normalImg'), result, WIDTH, HEIGHT))
  .catch(error => console.log(error));

  new NinePatch().getSize(srcImg)
  .then(result => setImage($('#testImg'), result.url, result.width + 50, result.height + 100))
  .catch(error => console.log(error));
});

function setImage(divElement, srcURL, width, height) {
  divElement.style.width = width + 'px';
  divElement.style.height = height + 'px';
  divElement.style.backgroundSize = '' + width + 'px ' + height + 'px'; 
  divElement.style.backgroundImage = "url('" + srcURL + "')";
}

References

  • Scale Nine-patch Image using NinePatch.js

Visit me

  • Complete JavaScript

About

⛏️ Scale a nine-patch image using JavaScript's canvas.

codepen.io/completejavascript/full/opOvaP

Topics

9patchcanvascanvas2djavascriptjsnine-patch

Resources

Readme
MIT license
Activity

Stars

17 stars

Watchers

1 watching

Forks

1 fork
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.