TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Using canvas to create alpha-channel JPEGs - 33% the size of PNGs

124 pointsby thegrossmanover 14 years ago

14 comments

jacobolusover 14 years ago
Instead of using canvas, for webkit at least it makes more sense to use <a href="http://webkit.org/blog/181/css-masks/" rel="nofollow">http://webkit.org/blog/181/css-masks/</a> Canvas is a good fall-back for other browsers.
评论 #1758486 未加载
评论 #1758525 未加载
mthomsover 14 years ago
For even bigger bandwidth savings paint a solid color over the non-visible portion of the jpg. There's no need to transmit all that image data if you aren't going to show it.<p>For this example I was able to quickly trim the jpg size from 35k to ~24k in about 60 seconds using Photoshop.
评论 #1758747 未加载
matthew-wegnerover 14 years ago
This was a common technique in game development a years ago, back when gospel was no larger than 10MB for downloadable casual games. You can get great compression with GIF/PNG for alpha channel and JPG or JPEG2000 for color data. The downside is you usually get multiple compression artifacts on screen (assuming texture compression like DXT), which doesn't apply for web use.
julian37over 14 years ago
I take it he means an 8-bit alpha channel, not a 24-bit alpha channel?<p>Anyway, here's the JPEG FAQ explaining why using JPEG for alpha wouldn't be a good idea even if it was supported: <a href="http://www.faqs.org/faqs/jpeg-faq/part1/section-12.html" rel="nofollow">http://www.faqs.org/faqs/jpeg-faq/part1/section-12.html</a>
评论 #1758671 未加载
评论 #1758678 未加载
nathanhammondover 14 years ago
One thing that hasn't been addressed is the cost of making the second image request. There is probably a break even point for this technique where it becomes useful, but the added complexity greatly limits its utility.
评论 #1758593 未加载
pornelover 14 years ago
Maybe this should be done by extending JPEG to support alpha channel?<p>It might have better chances for adoption than completely new format like WebP.<p>We'll just have another decade of complaining that IE doesn't support alpha, but we've been there and survived :)
评论 #1759146 未加载
Robin_Messageover 14 years ago
That is a neat implementation and a nice hack to implement it with XOR.<p>You've also taught me another valuable less: I created exactly this (actually with slightly different masking method) about a year ago, but I never got around to releasing it. Thank you for reminding me that <i>real artists ship.</i>
towndrunkover 14 years ago
Seems to crash safari on the iPad too.
onewlandover 14 years ago
Sure it's 33% the size of PNGs. It's 33% the quality. Am I the only person in existence who hates the "quantization" look?<p>edit: The strength of PNGs is not photography, but images with large blocks of solid colors; screenshots, etc. That's why the example in the article didn't suffer.
评论 #1759945 未加载
评论 #1760511 未加载
hartrorover 14 years ago
Neat hack, the lesson most of us should draw from this though is avoid designs that use big images with alpha transparency as they are many kbs! If you have to you maybe able to use this someday . . . for some of your users.
Raphaelover 14 years ago
Uses more requests, though.
jacquesmover 14 years ago
Now that is one very clever hack. It worked fine for me on ff 3.5.6.
juancferrerover 14 years ago
Yup. Crashes on iPad.
tzuryover 14 years ago
Smart Hack.
评论 #1759026 未加载