Plugin Directory

Changeset 3716956


Ignore:
Timestamp:
09/28/2026 10:52:41 AM (3 weeks ago)
Author:
adityapatadia
Message:

Update to version 1.4.4 from GitHub

Location:
gumlet
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • gumlet/tags/1.4.4/changelog.txt

    r3646686 r3716956  
    11== Changelog ==
     2
     3= 1.4.4 =
     4* Experimental things to enhance your user experience, checkout Plugin settings > Experimental
    25
    36= 1.4.3 =
  • gumlet/tags/1.4.4/gumlet.php

    r3646686 r3716956  
    1212 * Plugin URI:  https://github.com/gumlet/wordpress-plugin
    1313 * Description: A WordPress plugin to automatically load all your existing (and future) WordPress images via the <a href="http://www.gumlet.com" target="_blank">Gumlet</a> service for smaller, faster, and better looking images.
    14  * Version:     1.4.3
     14 * Version:     1.4.4
    1515 * Requires at least: 6.0
    1616 * Requires PHP: 7.4
  • gumlet/tags/1.4.4/includes/class-gumlet.php

    r3548638 r3716956  
    597597                }
    598598
    599                 if (in_array($src, $excluded_urls) || strpos($imageTag->getAttribute('fetchpriority'), "high") !== false) {
     599                // fetchpriority=high (LCP) images are rewritten server-side with a
     600                // responsive srcset so they get resized without waiting for gumlet.js.
     601                $is_priority = strpos($imageTag->getAttribute('fetchpriority'), "high") !== false;
     602
     603                if (in_array($src, $excluded_urls) || ($is_priority && !$this->get_option("optimize_priority_images"))) {
    600604                    $imageTag->setAttribute("data-gumlet", 'false');
    601605                    $new_img_tag = $doc->saveHTML($imageTag);
    … …  
    634638                    $auto_resize_on = $this->is_auto_resize_enabled();
    635639
     640                    if ($is_priority) {
     641                        $this->set_priority_image_attributes($imageTag, $gumlet_url);
     642                        $new_img_tag = $doc->saveHTML($imageTag);
     643                        $content = str_replace($unconverted_img_tag, $new_img_tag, $content);
     644                        continue;
     645                    }
     646
    636647                    if ($auto_resize_on) {
    637648                        $imageTag->setAttribute("data-gmsrc", $gumlet_url);
    638                         $imageTag->setAttribute("src", plugins_url('assets/images/pixel.png', __DIR__));
     649                        $imageTag->setAttribute("src", $this->get_placeholder_src($imageTag));
    639650                    } else {
    640651                        $imageTag->setAttribute("src", $gumlet_url);
    … …  
    655666                    $content = str_replace($unconverted_img_tag, $new_img_tag, $content);
    656667                } else {
     668                    if ($is_priority) {
     669                        $imageTag->setAttribute("data-gumlet", 'false');
     670                        $new_img_tag = $doc->saveHTML($imageTag);
     671                        $content = str_replace($unconverted_img_tag, $new_img_tag, $content);
     672                    }
    657673                    $this->logger->log("Skipping due to mismatched host to be replaced.");
    658674                }
    … …  
    663679        }
    664680        return $content;
     681    }
     682
     683    /**
     684     * Give a priority (LCP) image a real Gumlet src plus a width-based srcset,
     685     * so the browser picks a right-sized image without waiting for gumlet.js.
     686     *
     687     * @param DOMElement $imageTag
     688     * @param string     $gumlet_url
     689     */
     690    protected function set_priority_image_attributes($imageTag, $gumlet_url)
     691    {
     692        $max_width = (int) $imageTag->getAttribute('width');
     693        $max_width = $max_width > 0 ? $max_width * 2 : 2560;
     694
     695        $srcset = [];
     696        foreach ([320, 480, 640, 768, 1024, 1280, 1536, 1920, 2560] as $w) {
     697            if ($w > $max_width) {
     698                break;
     699            }
     700            $srcset[] = add_query_arg('w', $w, $gumlet_url) . ' ' . $w . 'w';
     701        }
     702
     703        $imageTag->setAttribute("src", add_query_arg('w', min(1280, $max_width), $gumlet_url));
     704        if ($srcset) {
     705            $imageTag->setAttribute("srcset", implode(', ', $srcset));
     706            if (!$imageTag->getAttribute('sizes')) {
     707                $imageTag->setAttribute("sizes", '100vw');
     708            }
     709        }
     710        $imageTag->setAttribute("data-gumlet", 'false');
     711        $imageTag->removeAttribute("data-gmsrc");
     712        $imageTag->removeAttribute("data-src");
     713        $imageTag->removeAttribute("data-srcset");
     714        $imageTag->removeAttribute("data-lazy-srcset");
     715        $imageTag->removeAttribute("data-lazy-src");
     716    }
     717
     718    /**
     719     * Transparent SVG placeholder with the image's own aspect ratio, so layout
     720     * (e.g. masonry grids) is correct before gumlet.js swaps in the real image.
     721     * Falls back to the 1x1 pixel when the option is off or width/height are unknown.
     722     *
     723     * @param DOMElement $imageTag
     724     * @return string
     725     */
     726    protected function get_placeholder_src($imageTag)
     727    {
     728        if (!$this->get_option("aspect_ratio_placeholder")) {
     729            return plugins_url('assets/images/pixel.png', __DIR__);
     730        }
     731        $width = (int) $imageTag->getAttribute('width');
     732        $height = (int) $imageTag->getAttribute('height');
     733        if ($width > 0 && $height > 0) {
     734            return "data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20" . $width . "%20" . $height . "'%3E%3C/svg%3E";
     735        }
     736        return plugins_url('assets/images/pixel.png', __DIR__);
    665737    }
    666738
  • gumlet/tags/1.4.4/includes/options-page.php

    r3488726 r3716956  
    260260                </table>
    261261            </div>
     262            <input type="radio" id="tabexperimental" name="mytabs">
     263            <label for="tabexperimental" class="mytablabel">Experimental</label>
     264            <div class="tab">
     265                <table class="form-table">
     266                    <tbody>
     267                        <tr>
     268                            <th>
     269                                <label class="description" for="gumlet_settings[optimize_priority_images]">
     270                                    <?php esc_html_e('Optimize Priority Images', 'gumlet'); ?>
     271                                </label>
     272                            </th>
     273                            <td>
     274                                <input id="gumlet_settings[optimize_priority_images]" type="checkbox"
     275                                    name="gumlet_settings[optimize_priority_images]" value="1" <?php
     276                                    checked($this->get_option('optimize_priority_images')) ?> />
     277                                <p style="color: #666">Serves your most important image (usually the hero or first
     278                                    image) through Gumlet at the right size for each screen, without waiting for
     279                                    Gumlet.js. WordPress and many themes mark this image with fetchpriority="high", and by
     280                                    default Gumlet leaves it untouched, so it loads at its full original size.
     281                                    <br>Turn this on to improve Largest Contentful Paint (LCP) and reduce mobile page
     282                                    weight. Recommended if your theme uses large banner or slider images.</p>
     283                            </td>
     284                        </tr>
     285                        <tr>
     286                            <th>
     287                                <label class="description" for="gumlet_settings[aspect_ratio_placeholder]">
     288                                    <?php esc_html_e('Aspect-Ratio Placeholders', 'gumlet'); ?>
     289                                </label>
     290                            </th>
     291                            <td>
     292                                <input id="gumlet_settings[aspect_ratio_placeholder]" type="checkbox"
     293                                    name="gumlet_settings[aspect_ratio_placeholder]" value="1" <?php
     294                                    checked($this->get_option('aspect_ratio_placeholder')) ?> />
     295                                <p style="color: #666">While an image is waiting to load, reserves space with the image's
     296                                    exact shape (from its width and height attributes) instead of a 1x1 square. This stops
     297                                    content from jumping as images load (better CLS) and fixes gaps in masonry grids,
     298                                    galleries and sliders that measure images while loading. Images without width and
     299                                    height use the default placeholder.
     300                                    <br>Turn this on if you see large gaps or overlapping content that corrects itself
     301                                    when the browser window is resized.</p>
     302                            </td>
     303                        </tr>
     304                    </tbody>
     305                </table>
     306            </div>
    262307        </div>
    263308        <input type="submit" class="button-primary" value="<?php esc_html_e('Save Options', 'gumlet'); ?>" />
  • gumlet/tags/1.4.4/readme.txt

    r3646686 r3716956  
    99Requires PHP: 7.4
    1010Tested up to: 7.1
    11 Stable tag: 1.4.3
     11Stable tag: 1.4.4
    1212License: BSD-2
    1313License URI: http://opensource.org/licenses/BSD-2-Clause
  • gumlet/trunk/changelog.txt

    r3646686 r3716956  
    11== Changelog ==
     2
     3= 1.4.4 =
     4* Experimental things to enhance your user experience, checkout Plugin settings > Experimental
    25
    36= 1.4.3 =
  • gumlet/trunk/gumlet.php

    r3646686 r3716956  
    1212 * Plugin URI:  https://github.com/gumlet/wordpress-plugin
    1313 * Description: A WordPress plugin to automatically load all your existing (and future) WordPress images via the <a href="http://www.gumlet.com" target="_blank">Gumlet</a> service for smaller, faster, and better looking images.
    14  * Version:     1.4.3
     14 * Version:     1.4.4
    1515 * Requires at least: 6.0
    1616 * Requires PHP: 7.4
  • gumlet/trunk/includes/class-gumlet.php

    r3548638 r3716956  
    597597                }
    598598
    599                 if (in_array($src, $excluded_urls) || strpos($imageTag->getAttribute('fetchpriority'), "high") !== false) {
     599                // fetchpriority=high (LCP) images are rewritten server-side with a
     600                // responsive srcset so they get resized without waiting for gumlet.js.
     601                $is_priority = strpos($imageTag->getAttribute('fetchpriority'), "high") !== false;
     602
     603                if (in_array($src, $excluded_urls) || ($is_priority && !$this->get_option("optimize_priority_images"))) {
    600604                    $imageTag->setAttribute("data-gumlet", 'false');
    601605                    $new_img_tag = $doc->saveHTML($imageTag);
    … …  
    634638                    $auto_resize_on = $this->is_auto_resize_enabled();
    635639
     640                    if ($is_priority) {
     641                        $this->set_priority_image_attributes($imageTag, $gumlet_url);
     642                        $new_img_tag = $doc->saveHTML($imageTag);
     643                        $content = str_replace($unconverted_img_tag, $new_img_tag, $content);
     644                        continue;
     645                    }
     646
    636647                    if ($auto_resize_on) {
    637648                        $imageTag->setAttribute("data-gmsrc", $gumlet_url);
    638                         $imageTag->setAttribute("src", plugins_url('assets/images/pixel.png', __DIR__));
     649                        $imageTag->setAttribute("src", $this->get_placeholder_src($imageTag));
    639650                    } else {
    640651                        $imageTag->setAttribute("src", $gumlet_url);
    … …  
    655666                    $content = str_replace($unconverted_img_tag, $new_img_tag, $content);
    656667                } else {
     668                    if ($is_priority) {
     669                        $imageTag->setAttribute("data-gumlet", 'false');
     670                        $new_img_tag = $doc->saveHTML($imageTag);
     671                        $content = str_replace($unconverted_img_tag, $new_img_tag, $content);
     672                    }
    657673                    $this->logger->log("Skipping due to mismatched host to be replaced.");
    658674                }
    … …  
    663679        }
    664680        return $content;
     681    }
     682
     683    /**
     684     * Give a priority (LCP) image a real Gumlet src plus a width-based srcset,
     685     * so the browser picks a right-sized image without waiting for gumlet.js.
     686     *
     687     * @param DOMElement $imageTag
     688     * @param string     $gumlet_url
     689     */
     690    protected function set_priority_image_attributes($imageTag, $gumlet_url)
     691    {
     692        $max_width = (int) $imageTag->getAttribute('width');
     693        $max_width = $max_width > 0 ? $max_width * 2 : 2560;
     694
     695        $srcset = [];
     696        foreach ([320, 480, 640, 768, 1024, 1280, 1536, 1920, 2560] as $w) {
     697            if ($w > $max_width) {
     698                break;
     699            }
     700            $srcset[] = add_query_arg('w', $w, $gumlet_url) . ' ' . $w . 'w';
     701        }
     702
     703        $imageTag->setAttribute("src", add_query_arg('w', min(1280, $max_width), $gumlet_url));
     704        if ($srcset) {
     705            $imageTag->setAttribute("srcset", implode(', ', $srcset));
     706            if (!$imageTag->getAttribute('sizes')) {
     707                $imageTag->setAttribute("sizes", '100vw');
     708            }
     709        }
     710        $imageTag->setAttribute("data-gumlet", 'false');
     711        $imageTag->removeAttribute("data-gmsrc");
     712        $imageTag->removeAttribute("data-src");
     713        $imageTag->removeAttribute("data-srcset");
     714        $imageTag->removeAttribute("data-lazy-srcset");
     715        $imageTag->removeAttribute("data-lazy-src");
     716    }
     717
     718    /**
     719     * Transparent SVG placeholder with the image's own aspect ratio, so layout
     720     * (e.g. masonry grids) is correct before gumlet.js swaps in the real image.
     721     * Falls back to the 1x1 pixel when the option is off or width/height are unknown.
     722     *
     723     * @param DOMElement $imageTag
     724     * @return string
     725     */
     726    protected function get_placeholder_src($imageTag)
     727    {
     728        if (!$this->get_option("aspect_ratio_placeholder")) {
     729            return plugins_url('assets/images/pixel.png', __DIR__);
     730        }
     731        $width = (int) $imageTag->getAttribute('width');
     732        $height = (int) $imageTag->getAttribute('height');
     733        if ($width > 0 && $height > 0) {
     734            return "data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20" . $width . "%20" . $height . "'%3E%3C/svg%3E";
     735        }
     736        return plugins_url('assets/images/pixel.png', __DIR__);
    665737    }
    666738
  • gumlet/trunk/includes/options-page.php

    r3488726 r3716956  
    260260                </table>
    261261            </div>
     262            <input type="radio" id="tabexperimental" name="mytabs">
     263            <label for="tabexperimental" class="mytablabel">Experimental</label>
     264            <div class="tab">
     265                <table class="form-table">
     266                    <tbody>
     267                        <tr>
     268                            <th>
     269                                <label class="description" for="gumlet_settings[optimize_priority_images]">
     270                                    <?php esc_html_e('Optimize Priority Images', 'gumlet'); ?>
     271                                </label>
     272                            </th>
     273                            <td>
     274                                <input id="gumlet_settings[optimize_priority_images]" type="checkbox"
     275                                    name="gumlet_settings[optimize_priority_images]" value="1" <?php
     276                                    checked($this->get_option('optimize_priority_images')) ?> />
     277                                <p style="color: #666">Serves your most important image (usually the hero or first
     278                                    image) through Gumlet at the right size for each screen, without waiting for
     279                                    Gumlet.js. WordPress and many themes mark this image with fetchpriority="high", and by
     280                                    default Gumlet leaves it untouched, so it loads at its full original size.
     281                                    <br>Turn this on to improve Largest Contentful Paint (LCP) and reduce mobile page
     282                                    weight. Recommended if your theme uses large banner or slider images.</p>
     283                            </td>
     284                        </tr>
     285                        <tr>
     286                            <th>
     287                                <label class="description" for="gumlet_settings[aspect_ratio_placeholder]">
     288                                    <?php esc_html_e('Aspect-Ratio Placeholders', 'gumlet'); ?>
     289                                </label>
     290                            </th>
     291                            <td>
     292                                <input id="gumlet_settings[aspect_ratio_placeholder]" type="checkbox"
     293                                    name="gumlet_settings[aspect_ratio_placeholder]" value="1" <?php
     294                                    checked($this->get_option('aspect_ratio_placeholder')) ?> />
     295                                <p style="color: #666">While an image is waiting to load, reserves space with the image's
     296                                    exact shape (from its width and height attributes) instead of a 1x1 square. This stops
     297                                    content from jumping as images load (better CLS) and fixes gaps in masonry grids,
     298                                    galleries and sliders that measure images while loading. Images without width and
     299                                    height use the default placeholder.
     300                                    <br>Turn this on if you see large gaps or overlapping content that corrects itself
     301                                    when the browser window is resized.</p>
     302                            </td>
     303                        </tr>
     304                    </tbody>
     305                </table>
     306            </div>
    262307        </div>
    263308        <input type="submit" class="button-primary" value="<?php esc_html_e('Save Options', 'gumlet'); ?>" />
  • gumlet/trunk/readme.txt

    r3646686 r3716956  
    99Requires PHP: 7.4
    1010Tested up to: 7.1
    11 Stable tag: 1.4.3
     11Stable tag: 1.4.4
    1212License: BSD-2
    1313License URI: http://opensource.org/licenses/BSD-2-Clause
Note: See TracChangeset for help on using the changeset viewer.