flip-xy.js 811 B

1234567891011121314151617181920212223
  1. export const flipXY = function (img) {
  2. // d b
  3. // q p
  4. const canvas = document.createElement('canvas');
  5. const width = img.width;
  6. const height = img.height;
  7. canvas.width = 2 * width;
  8. canvas.height = 2 * height;
  9. const ctx = canvas.getContext('2d');
  10. // top-left image
  11. ctx.drawImage(img, 0, 0, width, height);
  12. // xy-flipped bottom-right image
  13. ctx.setTransform(-1, 0, 0, -1, canvas.width, canvas.height);
  14. ctx.drawImage(img, 0, 0, width, height);
  15. // x-flipped top-right image
  16. ctx.setTransform(-1, 0, 0, 1, canvas.width, 0);
  17. ctx.drawImage(img, 0, 0, width, height);
  18. // y-flipped bottom-left image
  19. ctx.setTransform(1, 0, 0, -1, 0, canvas.height);
  20. ctx.drawImage(img, 0, 0, width, height);
  21. return canvas;
  22. };
  23. //# sourceMappingURL=flip-xy.js.map