 |
 User: Login | Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications. News and Articles about Designing and Developing wiht Yahoo! Libraries. |
| Address URL | http://yuiblog.com/blog Registered: 26-Apr-2008 |
| Ads: | |
Send to email | Image Transformations in Canvas with Slicing in Development | By Ross Harmes and Ernest Delgado el 23-Jun-2008 |
We’ve been obsessed with the canvas tag for a while now; we think it represents a huge opportunity for creative interfaces on the web, and current browser support for the tag is excellent (as long as you don’t mind using excanvas.js for IE6/7). That being said, there are some limitations. The only available built-in transformations are translation, rotationg and scale. Performing a complex transformation, such as keystoning an image so that it can be used in a faux 3D environment, has been difficult.
Foto 0 en Image Transformations in Canvas with Slicing: Paste this image in your site, Myspace, Facebook, Ebay copy this code...
However, there is an easy way to simulate arbitrary transformations on images in canvas. If you cut the image into slices, you can redraw each slice with different dimensions. The code is simple: using the slicing variation of the drawImage method, it’s possible to take a slice of a source image and draw it to the canvas. This slice can be scaled horizontally and vertically according to a formula. As the number of slices increases, the edges of the image become smoother and less jagged. It’s important to note that you only need one copy of the source image, and that drawing many slices doesn’t mean there are many copies of the image in the page. You are able to use one source image to draw multiple images on a destination canvas.
Creating a keystone effect looks complex but is actually very straightforward:
function keystoneAndDisplayImage(ctx, img, x, y, pixelWidth,
scalingFactor) {
var h = img.height,
w = img.width,
// The number of slices to draw.
numSlices = Math.abs(pixelWidth),
// The width of each source slice.
sliceWidth = w / numSlices,
// Whether to draw the slices in reverse order or not.
polarity = (pixelWidth > 0) ? 1 : -1,
// How much should we scale the width of the slice
// before drawing?
widthScale = Math.abs(pixelWidth) / w,
// How much should we scale the height of the slice
// before drawing?
heightScale = (1 - scalingFactor) / numSlices;
for(var n = 0; n < numSlices; n++) {
// Source: where to take the slice from.
var sx = sliceWidth * n,
sy = 0,
sWidth = sliceWidth,
sHeight = h;
// Destination: where to draw the slice to
// (the transformation happens here).
var dx = x + (sliceWidth * n * widthScale * polarity),
dy = y + ((h * heightScale * n) / 2),
dWidth = sliceWidth * widthScale,
dHeight = h * (1 - (heightScale * n));
ctx.drawImage(img, sx, sy, sWidth, sHeight,
dx, dy, dWidth, dHeight);
}
}
We take slices from the source image one at a time, apply a horizontal and vertical transformation, and then draw it in the correct order. This also allows us to do something interesting; if the slices are drawn in reverse order, we can reverse the image. The keystone demo page shows this code in action. The two sliders control the values entered into the function as pixelWidth and scalingFactor. Keystoning has a lot of potential applications. For instance, If you animate both width and scaling, you can create a page turning effect for any image.
Foto 1 en Image Transformations in Canvas with Slicing: Paste this image in your site, Myspace, Facebook, Ebay copy this code...
You can apply any transformation to the slices. If you were to scale the height of the slices based on a parabolic curve, you could create a cylindrical distortion that mimics a panorama view. We set up a Quicktime VR-style panorama using this technique. Be sure to view it with the rest of the canvas both shown and hidden to see how it works. It would also be possible to add an animating flag-ripple effect to any image, just by varying dy. We believe that image slicing transformations have a lot of applications in mimicing 3D environments and creating image effects. All you have to do is apply a formula to change the slice dimensions or position.
Read 5 times

|
|
 |
 |
 | Yahoo User Interface Blog | Blogger | Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications. Yahoo! User Interface Blog News and Articles about Designing and Developing wiht Yahoo! Libraries. |
| Image Transformations in Canvas with Slicing | We’ve been obsessed with the canvas tag for a while now; we think it represents a huge opportunity for creative interfaces on the web, and current browser support for the tag is excellent (as long as you don’t mind using excanvas.js for IE6/7). That being said, there are some limitations. The only available built-in transformations [...] [..] Read complete article |  | Published 23-Jun-2008 by Ross Harmes and Ernest Delgado in Development Read 5 times. More hits in  |
|
 | Kotaku`s The Gamers Guide | Blogger | XBOX 360 Gamers Weblog
Gossip, news and leaks for obsessive gamers Kotaku As if you don't waste enough of your time in a gamer's haze, here's Kotaku: a gamer's guide that goes beyond the press release. Gossip, cheats, criticism, design, nostalgia, pred |
| Adult Anime Drawings Forged in Halo 3 [Maximum Risky] | | We've previously seen how Halo 3's Forge can be used as a canvas by the artistically included. And while the above image is certainly not the first "erotic" images made with Forge level editor by a damn sight. (Hey, give the plebs the ability to create, and you betcha [..] Read complete article |  | Published 07-Jul-2008 by Brian Ashcraft in maximum risky Bungie forge Halo 3 Japan The forge Read 2 times. More hits in ![Images about Adult Anime Drawings Forged in Halo 3 [Maximum Risky]](./images/photo.gif) |
|
 | Kotaku`s The Gamers Guide | Blogger | XBOX 360 Gamers Weblog
Gossip, news and leaks for obsessive gamers Kotaku As if you don't waste enough of your time in a gamer's haze, here's Kotaku: a gamer's guide that goes beyond the press release. Gossip, cheats, criticism, design, nostalgia, pred |
 | Nerdblog | Blogger | Provides news about hardware, software, notebooks, laptops, PCs, Mac, PDAs Nerdblog.Net |
 | Nerdblog | Blogger | Provides news about hardware, software, notebooks, laptops, PCs, Mac, PDAs Nerdblog.Net |
| LEGO NXT image scanner | | Anders Søborg built an amazing scanner that can use either the light sensor that comes with the NXT or a HiTechnic color sensor.
Each line of the image is created by moving the sensor over the image at a constant speed while recording the position and corresponding sensor values with a fixed sample rate. The [...] [..] Read complete article |  | Published 10-Jun-2008 by Nerdblog in General Read 5 times. More hits in  |
|
| Microsoft tries to take their image back | In continuing with its new and “clever” line of advertising, Microsoft has temporarily ditched the Gates/Seinfeld ads in favor of reclaiming their image from Apple. As you can see in the image above, it doesn’t seem like they’re really doing themselves a huge favor by taking one of their very own employees and dressing him [...]
[..] Read complete article |  | Published 18-Sep-2008 by Marc Flores in AppleGeneralMac OSNewsOpinionsWindows VistaWindows XPAdsBill GatesMacmicrosoftPCSeinfeldWindows Read 1 times. More hits in  |
|
 | Kotaku`s The Gamers Guide | Blogger | XBOX 360 Gamers Weblog
Gossip, news and leaks for obsessive gamers Kotaku As if you don't waste enough of your time in a gamer's haze, here's Kotaku: a gamer's guide that goes beyond the press release. Gossip, cheats, criticism, design, nostalgia, pred |
 | Yahoo User Interface Blog | Blogger | Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications. Yahoo! User Interface Blog News and Articles about Designing and Developing wiht Yahoo! Libraries. |
| David Cilley?s Tutorial Series on Ajax Image Sliders | David Cilley this week published the second in his series of articles on using the YUI Slider Control to provide real-time previewing of image changes.
Part 1: The OnDemand method.
Part 2: The Interval method.
In this second installment, David takes on the challenge of making the preview feel instantaneous without computing or delivering every possible image represented [...] [..] Read complete article |  | Published 24-Apr-2008 by Eric Miraglia in Developmentdavid cilleyimagesslidertutorialyui Read 5 times. More hits in  |
|
 | Joystiq | Blogger | Covers video game news from an independent, unbiased perspective Joystiq Joystiq |
 | Kotaku`s The Gamers Guide | Blogger | XBOX 360 Gamers Weblog
Gossip, news and leaks for obsessive gamers Kotaku As if you don't waste enough of your time in a gamer's haze, here's Kotaku: a gamer's guide that goes beyond the press release. Gossip, cheats, criticism, design, nostalgia, pred |
Wii Ski and Snowboard: EXCITING [Wii Ski And Snowboard] | | Sure, nothing can top a Japanese guy with a gi-normous Afro faux slicing up undead ninja, but it was still pretty cool to watch someone playing Wii Ski and Snowboard using the balance board, remote and nunchuk. [..] Read complete article |  | Published 07-Oct-2008 by Brian Crecente in Wii ski and snowboard Namco Bandai Original Tgs08 Tokyo game show 2008 Video Read 0 times. More hits in ![Images about Wii Ski and Snowboard: EXCITING [Wii Ski And Snowboard]](./images/photo.gif) |
|
 | Joystiq | Blogger | Covers video game news from an independent, unbiased perspective Joystiq Joystiq |
| See the first image from Quantum of Solace | Filed under: Sony PlayStation 3, Microsoft Xbox 360, First Person Shooters
Interested to see what Treyarch is doing with the 007 license? GamesRadar has obtained the first image of Quantum of Solace, built on th [..] Read complete article |  | Published 20-Jun-2008 by Ross Miller in 007james-bondquantum-of-solace Read 3 times. More hits in  |
|
 | Kotaku`s The Gamers Guide | Blogger | XBOX 360 Gamers Weblog
Gossip, news and leaks for obsessive gamers Kotaku As if you don't waste enough of your time in a gamer's haze, here's Kotaku: a gamer's guide that goes beyond the press release. Gossip, cheats, criticism, design, nostalgia, pred |
|
Warning We are not responsible of information posted from external feeds. Use this website at your own risk.
Notice: We will not be liable for any direct or indirect loss or damage arising under this disclaimer or in connection with our website, whether arising in tort, contract, or otherwise.
|
|
| |