Fullscreen image in Canvas
How do I make an fullscreen image in canvas?
In a project, I needed to draw image fullscreen in canvas.. What is a fullscreen image in canvas? How do you make a fullscreen image in canvas? This script and codes were developed by Chrysto on 16 July 2022, Saturday.
Fullscreen image in Canvas - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Fullscreen image in Canvas</title> <script src="http://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="canvas__holder"> <canvas id="image__canvas"> </canvas>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Fullscreen image in Canvas - Script Codes CSS Codes
body, html, div, canvas { margin: 0; padding: 0; outline: none; box-sizing: border-box;
}
Fullscreen image in Canvas - Script Codes JS Codes
$(function() { var $window = $(window), $canvasHolder = $(".canvas__holder"), $canvas = $("#image__canvas"), canvas = $canvas.get(0), canvasContext = canvas.getContext("2d") var winWidth, winHeight, winRatio, imgWidth, imgHeight, imgRatio, canvasInited; var img; var $img = $("<img />", { "src": "http://ivayloyovchev.com/pulsepro/data/img/gallery/personal/IMG_0010_.jpg" }).load(function() { img = $img.get(0); imgWidth = img.width; imgHeight = img.height; imgRatio = imgWidth / imgHeight; canvasInited = true; resizeCanvas(); }); $window.on("resize", onResize); $window.trigger("resize"); function onResize() { winWidth = $window.width(); winHeight = $window.height(); winRatio = winWidth / winHeight; $canvas.attr({ "width": winWidth + "px", "height": winHeight + "px" }); $canvasHolder.add($canvas).css({ "width": winWidth + "px", "height": winHeight + "px" }); if (canvasInited) { resizeCanvas(); } } function resizeCanvas() { var newWidth = winWidth, newHeight = winHeight, newX = 0, newY = 0; if (winRatio > imgRatio) { newHeight = Math.round(winWidth / imgRatio); newY = (winHeight - newHeight) / 2; } else { newWidth = Math.round(winHeight * imgRatio); newX = (winWidth - newWidth) / 2; } canvasContext.drawImage(img, newX, newY, newWidth, newHeight); }
});
Developer | Chrysto |
Username | bassta |
Uploaded | July 16, 2022 |
Rating | 3 |
Size | 2,268 Kb |
Views | 30,360 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Click outside element | 1,993 Kb |
Smooth scroll | 4,915 Kb |
Fullscreen Parallax | 3,313 Kb |
Medium.com style header effect | 2,828 Kb |
One page website scrolling effect | 2,764 Kb |
Simple one page header concept | 2,530 Kb |
Lastik menu | 2,257 Kb |
Single page website | 2,688 Kb |
GIF-like animation with single image | 1,807 Kb |
Footer concept | 2,210 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Tooltip in table | Roine | 3,713 Kb |
Basic template | Tomcat | 1,675 Kb |
Horizontal slider on scroll | Alojzije | 2,672 Kb |
Flat UI - Checkbox FIX | ARS | 2,663 Kb |
A cube | KyleDavidE | 18,627 Kb |
Loading animation - freedom purchase | Rocbear | 2,567 Kb |
React TODO | Enieste | 3,320 Kb |
Static Image to Video Block | Grayghostvisuals | 4,864 Kb |
Welcome | Nakome | 6,076 Kb |
Fluid Responsive Typography | Jonmilner | 4,205 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!