LOGO IMAGE ENHANCED
===================

Applies an image style and the right HTML attributes (width, height, alt,
title, loading, fetchpriority, decoding) to the site logo, directly in the
HTML sent by the server.


CONTENTS
--------
1. What it does
2. Why use it
3. Requirements
4. Installation
5. Configuration
6. How it works
7. Updating from 1.0.2 or earlier
8. Troubleshooting
9. For developers


1. WHAT IT DOES
---------------
Core themes print the logo like this:

  <img src="/themes/custom/mytheme/logo.png" alt="Home" fetchpriority="high" />

With this module enabled and an image style selected, the same logo is sent
as:

  <img src="/sites/default/files/styles/logo_header/public/logo.webp?itok=..."
       alt="My Site" title="My Site" width="240" height="218"
       loading="eager" fetchpriority="high" />

- The logo uses the selected image style (resize, crop, convert).
- width and height are always present, so the browser reserves the space
  and the header does not jump while the page loads.
- alt and title use your text instead of "Home".
- No JavaScript is needed for the logo of the Site branding block.


2. WHY USE IT
-------------
- Performance: a logo without width/height causes layout shift (CLS) in
  PageSpeed / Core Web Vitals. A resized logo also weighs less.
- Accessibility: alt="Home" does not describe the logo.
- Works with any theme, including themes based on Starterkit or Classy whose
  template only prints the logo URL.


3. REQUIREMENTS
---------------
- Drupal 10.3 or later, or Drupal 11.
- Image module (Drupal core).
- Supported logo formats: PNG, GIF, JPG, JPEG, APNG, SVG, WebP, AVIF.


4. INSTALLATION
---------------
  composer require drupal/logo_image_enhanced
  drush en logo_image_enhanced

Or place the module in modules/contrib/ and enable it at Extend.


5. CONFIGURATION
----------------
Go to Appearance > Settings (global) or Appearance > [theme] > Settings.
The logo file itself is set in the core "Logo image" section of that page.
The "Logo Image Enhanced" section below it has these options:

  Image Style
    Image style applied to the logo. "None" keeps the original file.
    Formats the image toolkit cannot process (SVG, or AVIF without toolkit
    support) always use the original file.

  Alt Text
    Text for screen readers. Defaults to the site name.

  Title
    Tooltip on hover. Defaults to the site name.

  Image loading attribute
    "Eager" (recommended for a logo above the fold) or "Lazy".

  Fetchpriority attribute
    "Keep the theme value" leaves what the template prints (core themes
    print "high"). "Remove" deletes it; use it when the logo is not the
    largest image above the fold so it does not compete with a hero image.
    "High", "Low" and "Auto" set that value.

  Decoding attribute
    Same choices as fetchpriority, for the decoding attribute.

  Also fix logos printed outside the branding block
    Off by default. Turn it on only if your theme prints the logo somewhere
    other than the Site branding block. It loads a small script on every page
    that applies these settings to those other logo images.

  Enable debug mode
    Shows a diagnostic panel to administrators at the bottom of each page.
    Turn it off in production.

Important:
- These options are shared by all themes.
- The logo file always comes from the theme settings, exactly the one Drupal
  renders. A theme with its own logo settings overrides the global ones, so
  saving the global page does not change the logo of that theme.


6. HOW IT WORKS
---------------
1. The module reads the logo of the active theme from the theme settings.
2. Before the Site branding block is rendered, the logo URL is replaced by
   the image style URL.
3. After the block is rendered, the module finds the <img> whose src is the
   logo (styled or original, relative or absolute URL) and writes the
   attributes. Other images in the block are not touched and no attribute is
   duplicated.
4. width/height come from the styled image, from the original file when no
   style is used, or from the width/height or viewBox of an SVG.
5. The result is cached with the block. Changing the module settings, the
   theme settings or the image style updates it without clearing caches.

Note for SVG logos: when an SVG has only a viewBox, its viewBox size is used
as width/height. If your CSS does not limit the logo size, the logo is shown
at that size.


7. UPDATING FROM 1.0.2 OR EARLIER
---------------------------------
Replace the module files, then run:

  drush updb -y && drush cr

The update removes the old module "logo_path" setting (the logo now always
follows the theme) and removes module values that older versions saved by
mistake into system.theme.global and <theme>.settings.

Since 1.0.3 the JavaScript fallback is off by default. If your theme prints
the logo outside the Site branding block, enable "Also fix logos printed
outside the branding block" again.


8. TROUBLESHOOTING
------------------
The logo has no width/height or keeps alt="Home"
  - Check that the logo is shown by the Site branding block. If not, enable
    "Also fix logos printed outside the branding block".
  - Enable debug mode and check "URI (from theme settings)" and
    "Dimensions" in the panel.

The old logo still appears
  - Check the logo set for the theme you are viewing, not only the global
    settings.
  - With the contrib "webp" module: if a .png or .jpg with the same name sits
    next to a .webp logo, that file is used as the source of the styled
    image (old logo, or a 403 error if the style converts the format).
    Rename or remove the sibling file. The settings page and the debug panel
    warn about this.

The style is not applied
  - The image toolkit may not support the format (for example AVIF on
    some servers). The debug panel shows "format not supported".


9. FOR DEVELOPERS
-----------------
Files:
  logo_image_enhanced.module         Hooks, settings form, logo helpers.
  src/Render/LogoPreRenderCallback   Sets the styled logo URL.
  src/Render/LogoPostRenderCallback  Writes the <img> attributes.
  logo_image_enhanced.install        Install and update hooks.
  js/logo-attributes.js              Optional fallback for other logos.
  js/logo-diagnostic.js              Debug panel.

Configuration object: logo_image_enhanced.settings
  logo_style          Image style ID, or "_none".
  logo_alt            Alt text.
  logo_title          Title text.
  logo_loading        "eager" or "lazy".
  logo_fetchpriority  "_none" (keep), "remove", "high", "low" or "auto".
  logo_decoding       "_none" (keep), "remove", "async", "sync" or "auto".
  js_fallback         TRUE to load the fallback script.
  debug_enabled       TRUE to show the debug panel.

Templates of block--system-branding-block also receive a "logo_enhanced"
variable (alt, title, loading, fetchpriority, decoding), kept for backward
compatibility. Processed images carry data-logo-enhanced="server" (or
"client" when set by the fallback script).

See CHANGELOG.md for the changes in each version.
