Create Canvas Image with jQuery
I usually use <img tag to create images almost for everything. However one day I stuck with the iPad being limited to load more than 8MB of images into one page. Eventually I had to replace all of my <img tags with the <canvas element. Below is a simple example how you can create canvas image element. The only trick with canvas is that you have to fill it up with image and resize only when image is completely loaded.
var loadCanvas = function(src) { var canvas = document.createElement("canvas"); var context = canvas.getContext("2d"); var img = new Image(); img.src = src; $(img).load(function(){ canvas.width = img.width; canvas.height = img.height context.drawImage(this, 0, 0); }); return $(canvas); };
Dima Svirid
Software architect. Ajax/Javascript, HTML5, Android, iPhone/iPad, JAVA, PHP, Cold Fusion, SQL, Air, Flash, Open source software, Frameworks
SEARCH ARTICLES & TUTORIALS
MOST POPULAR TUTORIALS
Generating PDF Documents with Adobe Air Javascript SDK and jQuery
I am not a Flex guy and I don't think I will ever be. While searching [...]
Search Engine Optimization - Do It Yourself!
This is Part 1 of "Search Engine Optimization – Do It Yourself!" ser[...]
jQuery Object Oriented Plugins
Many people have asked me, if jQuery is object oriented and how they c[...]
Spring-MVC Tutorial (Part 1)
Overview This document is a step-by-step guide on how to de[...]
Animated scroll to anchor method with jQuery
It's a one line but can add a really nice effect to your website. f[...]
RECENT POSTS
Eclipse Keyboard Shortcuts for Developers
Eclipse Navigation Shortcuts Every Java Programmer Should Know Ctrl [...]
Duplicated Content
This is Part 4 of "Search Engine Optimization – Do It Yourself!" ser[...]
301 Redirect
There are many ways how you can do 301 redirect, I will mention just t[...]
Friendly URL for SEO (Permalinks)
This is Part 5 of "Search Engine Optimization – Do It Yourself!" ser[...]
Generating PDF Documents with Adobe Air Javascript SDK and jQuery
I am not a Flex guy and I don't think I will ever be. While searching [...]