Coder Social home page Coder Social logo

factmaven / specify-image-dimensions Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 12 KB

Specify Image Dimensions is a plugin that scans and inserts missing width and height in all <img> tags. Specifying the dimension allows for faster rendering by eliminating the need for unnecessary re-flows and repaints. This is particularly helpful with website speed tools such as GTmetrix and Google's PageSpeed.

Home Page: https://wordpress.org/plugins/specify-image-dimensions/

PHP 100.00%
wordpress wordpress-plugin image-dimensions width width-calculation height height-calculation repaints inserts-missing php

specify-image-dimensions's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

nate-allen

specify-image-dimensions's Issues

SVG & webP images are given size "0" dimensions

Also mentioned in the support thread here, SVG and webP images are given a value of "0" in the width and height when they are not assigned.

Possible fixes:

  • Only specify image dimensions to common image types (jpeg, jpg, png, gif)
  • If image is a SVG/webP, apply width=100% and height=auto

Perhaps an option can be added for the second point to allow users decide if they still want to add dimensions to SVG/webP.

Blank height and width attributes

Reference: Blank height and width attributes

When there are images that have blank dimensions (for both width and height), the plugin doesn't detect it:

<img src="https://placehold.it/100x50" width="" height="">

However, when there is only one blank dimension, my plugin does catch it. The following two examples will work:

<img src="https://placehold.it/100x50" width="">
<img src="https://placehold.it/100x50" height="">

Removes javascript events on img tags

WordPress user (Sandra) found a bug that make some attributes disappear. So this code turns out like this:

<img id="rating_1952_1" src="https://www.foodcat.de/wp-content/plugins/wp-postratings/images/stars_flat(png)/rating_off.png" alt="1 Stern" title="1 Stern" onmouseover="current_rating(1952, 1, '1 Stern');" onmouseout="ratings_off(0, 0, 0);" onclick="rate_post();" onkeypress="rate_post();" style="cursor: pointer; border: 0px;">
<img src="https://www.foodcat.de/wp-content/plugins/wp-postratings/images/stars_flat(png)/rating_off.png" alt="1 Stern" id="rating_1952_1" width="17" height="16">

Here is the fix she provided:

# Match all image attributes
$attributes = 'src|srcset|longdesc|alt|class|id|usemap|align|border|hspace|vspace|crossorigin|ismap|sizes|title|onmouseover|onmouseout|onclick|onkeypress|style|width|height';

โ€ฆ

# Recreate the image tag with dimensions set
$tag = sprintf( '<img src=%s%s%s%s%s%s%s%s%s%s%s

Please apply the fix and test locally. Once it works out, then push to production and apply bug fix credit.

Reference: https://wordpress.org/support/topic/removes-javascript-events-on-img-tags/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.