• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Dynamic Font Colors

Scheduled Pinned Locked Moved Custom CSS
8 Posts 3 Posters 386 Views 4 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    MMRIZE @ijoshea
    last edited by MMRIZE Jul 7, 2024, 12:59 PM Jul 7, 2024, 12:59 PM

    @ijoshea
    It seems weird to import JS in css.

    S 1 Reply Last reply Jul 7, 2024, 1:16 PM Reply Quote 0
    • S Away
      sdetweil @MMRIZE
      last edited by Jul 7, 2024, 1:16 PM

      @MMRIZE AND it doesn’t work…

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      1 Reply Last reply Reply Quote 0
      • S Away
        sdetweil @ijoshea
        last edited by sdetweil Jul 7, 2024, 1:31 PM Jul 7, 2024, 1:18 PM

        @ijoshea I added the scripts to MMM-ImagesPhotos (getScripts response)
        and they are loaded… BUT the document on(‘load’) from the script above doesn’t fire…
        I don’t know if that is because in my version of MMM-ImagesPhotos I set an onload for each image loaded so that I can adjust the size to keep the aspect ratio from the image
        (css cover and contain both adjust the aspect ratio)

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        1 Reply Last reply Reply Quote 0
        • M Offline
          MMRIZE @ijoshea
          last edited by MMRIZE Jul 7, 2024, 2:40 PM Jul 7, 2024, 2:38 PM

          @ijoshea
          I had the same needs on building modules. (btw, GooglePhotos and CX3 were built by me :D )

          Sometimes I suggested other module’s background for the readability. Sometimes, I made an auto-calculated contrast color(e.g. CX3)

          My final conclusion is… waiting for new CSS feature contrast-color(). It will be introduced later this year in the most modern browsers.
          https://drafts.csswg.org/css-color-5/#contrast-color

          1 Reply Last reply Reply Quote 1
          • M Offline
            MMRIZE @ijoshea
            last edited by Jul 8, 2024, 11:57 AM

            @ijoshea
            Anyway, It looks so interesting, So I tried something. I simply did monkey patching to get dominant color from MMM-GooglePhotos’s image on load.

            6e971ed4-d102-434d-98e3-fd9d1de48374-image.png
            You can do your job with this code without modifying the source codes itselfs.

            /* config/config.js */
            {
            	module: "MMM-ModuleMonkeyPatch",
            	config: {
            		patches: [
            			{
            				module: "MMM-GooglePhotos",
            				method: "ready",
            				patch: async function (original, [ url, target ]) {
            					const ret = original(url, target)
            					let color = null
            					const process = async () => {
            						const { resolve, promise } = Promise.withResolvers()
            						const img = new Image()
            						img.crossOrigin = 'Anonymous'
            						img.src = 'https://corsproxy.io/?' + url
            						img.onload = () => {
            							const colorThief = new ColorThief()
            							const color = colorThief.getColor(img)
            							resolve(color)
            						}
            						return promise
            					}
            					if (typeof ColorThief === 'undefined') {
            						const loadScript = async (src) => {
            							const { resolve, promise } = Promise.withResolvers()
            							const script = document.createElement('script')
            							script.src = src
            							document.head.appendChild(script)
            							script.onload = () => resolve()
            							return promise
            						}
            						await loadScript('https://cdn.jsdelivr.net/npm/colorthief@2/dist/color-thief.min.js')
            						color = await process()
            
            					} else {
            						color = await process()
            					}
            
            					console.log(color) // It will show [R, G, B] array
            					// doYourJob(color)
            
            					return ret
            				},
            			},
            		],
            	},
            },
            
            I 1 Reply Last reply Jul 11, 2024, 12:09 AM Reply Quote 1
            • I Offline
              ijoshea @MMRIZE
              last edited by Jul 11, 2024, 12:09 AM

              @MMRIZE @sdetweil thanks for the help. I havent had a chance to play around with it on my set up but looks to be going in the right direction!

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              1 / 1
              • First post
                7/8
                Last post
              Enjoying MagicMirror? Please consider a donation!
              MagicMirror created by Michael Teeuw.
              Forum managed by Sam, technical setup by Karsten.
              This forum is using NodeBB as its core | Contributors
              Contact | Privacy Policy