Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 4130

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 26, 20242024-11-26T09:08:09+00:00 2024-11-26T09:08:09+00:00

Why “dark mode” is more energy-efficient: How to calculate image energy-cost

  • 61k

When I read Tom Greenfords execellent book Sustainable Web Design, there was one fact that stuck with me in particular:

Running Google Maps in night mode reduced screen power draw by 63 percent.

Why is that?

When you think about it, it's quite simple:

Black is the most efficient color for OLED screens as the pixels are switched off, and white is the most energy intensive

So images use different amounts of energy, depending on the intensity of the red, green and blue lights in the pixel.

Tom goes on to show two examples of his website before and after an update:

Before:
Before

After:
After

The latter use almost half the energy of the first one!

Unebelievable, right?

So – I sat out to create a small tool for calculating the energy-intensity of an image!


Draw the image onto a <canvas>

The <canvas>-tag has a really useful method: getImageData(), which will return a (very large!) array of all the pixels in an image – in chunks of 4: red, green, blue and alpha:

const imgData = ctx.getImageData(0, 0, width, height); 
Enter fullscreen mode Exit fullscreen mode

With this array, we can iterate and return an array of percentages:

const len = imgData.data.length / 4;  let r = 0, g = 0, b = 0, a = 0; for (let i = 0; i < imgData.data.length; i += 4) {   a = 255 / imgData.data[i + 3];   r+= imgData.data[i] / 255 / a;   g+= imgData.data[i + 1] / 255 / a;   b+= imgData.data[i + 2] / 255 / a; } r = Math.floor((r/len) * 100); g = Math.floor((g/len) * 100); b = Math.floor((b/len) * 100);  return [r, g, b]; 
Enter fullscreen mode Exit fullscreen mode

To get the average:

const avg = Math.ceil((r+g+b) / 3); 
Enter fullscreen mode Exit fullscreen mode

The tool is on Codepen – try uploading your own image to check the light/energy intensity.

The initial image is a pure rgb-color-image, with blue set to 127: rgb(0, 0, 127). That results in:

R: 0% G: 0% B: 49% Average: 17%  
Enter fullscreen mode Exit fullscreen mode


But … It's Not So Simple

While this tool will give you a hint about the energy-usage of an image, it's much more complex than that.

The photon energy differs for different wavelengths, with red being lowest and violet being highest.

A pixel contains approx. 10.000 photons, so I assume it's possible to calculate the eV cost of an image in a particular resolution – and then convert that number to Watt – but it's beyond my skills!

Conclusion

It would be nice, if a tool like Lighthouse could calculate the energy-effectiveness of a website – perhaps compared to a list of how much energy popular devices use, when all pixels are either black or white.

This way you could test how much battery drain you could prevent by designing darker websites!

Thanks for reading!

htmljavascriptperformancewebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.