Plugin Directory

Changeset 2064930


Ignore:
Timestamp:
04/08/2019 09:34:42 AM (7 years ago)
Author:
iprodev
Message:

Version 1.1.3

Location:
easy-lazy-loader/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • easy-lazy-loader/trunk/easy-lazy-loader.php

    r1747658 r2064930  
    22/*
    33Plugin Name: Easy Lazy Loader
    4 Version: 1.1.2
    5 Plugin URI: https://www.iprodev.com/go/easy-lazy-loader/
     4Version: 1.1.3
     5Plugin URI: https://www.iprodev.com/easy-lazy-loader/
    66Author: iProDev
    77Author URI: https://www.iprodev.com/
     
    619619                // don't to the replacement if the image is a data-uri
    620620                if ( ! preg_match( "/src=['\"]data:image/is", $imgHTML ) ) {
     621
     622                    if ( 'color' === $placeholder_type && ( !class_exists( 'WordPress_Gallery_Extra' ) ) ) {
     623                        $placeholder_type = 'default';
     624                    }
    621625                   
    622626                    $placeholder_url_used = $placeholder_url;
     
    635639                        }
    636640                        // use color as placeholder if applicable
    637                         else if ( 'color' === $placeholder_type && class_exists( 'WordPress_Gallery_Extra' ) ) {
     641                        else if ( 'color' === $placeholder_type ) {
    638642                            $placeholder_color = "";
    639643
     
    939943         * @return string The placeholder datauri
    940944         */
    941         public static function create_placeholder( $background = '#FFF', $width = 1, $height = 1, $text = "" ) {
     945        public static function create_placeholder( $background = '#FFFFFF', $width = 1, $height = 1, $text = "" ) {
    942946            if ( $width >= 30 && $height >= 30 ) {
    943947                $new_dimensions = wp_constrain_dimensions( $width, $height, 30, 30 );
     
    955959            }
    956960
    957             // Create a new image instance
    958             $image = imagecreatetruecolor( $width, $height );
    959 
    960             if ( $background ) {
    961                 // Parse color and fill bg
    962                 $color = self::hex2rgb( $background );
    963                 $back = imagecolorallocate( $image, $color['r'], $color['g'], $color['b'] );
    964 
    965                 // Make the background
    966                 imagefilledrectangle( $image, 0, 0, $width, $height, $back );
     961            if ( extension_loaded( 'imagick' ) ) {
     962                $image = new Imagick();
     963                $image->newImage( $width, $height, new ImagickPixel( $background ) );
     964                $image->setImageFormat('gif');
     965                return "data:image/gif;base64," . base64_encode( $image );
     966            } else if ( extension_loaded( "gd" ) ) {
     967                // Create a new image instance
     968                $image = imagecreatetruecolor( $width, $height );
     969
     970                if ( $background ) {
     971                    // Parse color and fill bg
     972                    $color = self::hex2rgb( $background );
     973                    $back = imagecolorallocate( $image, $color['r'], $color['g'], $color['b'] );
     974
     975                    // Make the background
     976                    imagefilledrectangle( $image, 0, 0, $width, $height, $back );
     977                } else {
     978                    $black = imagecolorallocate( $image, 0, 0, 0 );
     979                    imagecolortransparent( $image, $black );
     980                }
     981
     982                /*if ( $text ) {
     983                    $font_size = 15;
     984                    $text_width = imagefontwidth( $font_size ) * strlen( $text );
     985                    $text_height = imagefontheight( $font_size );
     986
     987                    if ( $width >= $text_width && $height >= $text_height ) {
     988                        $brightness = (299 * $color['r'] + 587 * $color['g'] + 114 * $color['b']) / 1000;
     989                        $text_color = $brightness > 127 ? array( 0, 0, 0 ) : array( 255, 255, 255 );
     990                        $text_color = $brightness > 127 ? array( 0, 0, 0 ) : array( 255, 255, 255 );
     991                        $textcolor = imagecolorallocate( $image, $text_color[0], $text_color[1], $text_color[2] );
     992                        imagestring( $image, $font_size, ( $width / 2 ) - ( $text_width / 2 ), ( $height / 2 ) - ( $text_height / 2 ), $text, $textcolor );
     993                    }
     994                }*/
     995
     996                ob_start();
     997
     998                imagegif( $image );
     999
     1000                $data = ob_get_contents();
     1001                ob_end_clean();
     1002
     1003                imagedestroy( $image );
     1004                return "data:image/gif;base64," . base64_encode( $data );
    9671005            } else {
    968                 $black = imagecolorallocate( $image, 0, 0, 0 );
    969                 imagecolortransparent( $image, $black );
    970             }
    971 
    972             /*if ( $text ) {
    973                 $font_size = 15;
    974                 $text_width = imagefontwidth( $font_size ) * strlen( $text );
    975                 $text_height = imagefontheight( $font_size );
    976 
    977                 if ( $width >= $text_width && $height >= $text_height ) {
    978                     $brightness = (299 * $color['r'] + 587 * $color['g'] + 114 * $color['b']) / 1000;
    979                     $text_color = $brightness > 127 ? array( 0, 0, 0 ) : array( 255, 255, 255 );
    980                     $text_color = $brightness > 127 ? array( 0, 0, 0 ) : array( 255, 255, 255 );
    981                     $textcolor = imagecolorallocate( $image, $text_color[0], $text_color[1], $text_color[2] );
    982                     imagestring( $image, $font_size, ( $width / 2 ) - ( $text_width / 2 ), ( $height / 2 ) - ( $text_height / 2 ), $text, $textcolor );
    983                 }
    984             }*/
    985 
    986             ob_start();
    987 
    988             imagegif( $image );
    989 
    990             $data = ob_get_contents();
    991             ob_end_clean();
    992 
    993             imagedestroy( $image );
    994             return "data:image/gif;base64," . base64_encode( $data );
     1006                return "data:image/gif;base64,R0lGODlhAQABAHAAACH5BAUAAAAALAAAAAABAAEAQAICRAEAOw==";
     1007            }
    9951008        }
    9961009
     
    10201033
    10211034            $uploads_directory = wp_upload_dir();
     1035            $uploads_directory_path = dirname( parse_url( $uploads_directory['baseurl'], PHP_URL_PATH ) );
     1036            $image_src_path         = dirname( parse_url( $image_src, PHP_URL_PATH ) );
     1037
     1038            if ( stripos( $image_src_path, $uploads_directory_path ) === false ) {
     1039                return false;
     1040            }
     1041
    10221042            $image_src = preg_replace( "/-[0-9]+x[0-9]+./i", '.', $image_src );
    10231043            $image_src = str_replace( $uploads_directory['baseurl'] . "/", "", $image_src );
  • easy-lazy-loader/trunk/readme.txt

    r2047510 r2064930  
    1 === Easy Lazy Loader ===
     1=== Easy Lazy Loader ===
    22Contributors: iprodev
    3 Donate link: https://iprodev.com/easy-lazy-loader
     3Donate link: https://www.iprodev.com/easy-lazy-loader
    44Tags: lazy load, images, videos, audios, iframes, front-end optimization
    55Requires at least: 3.2
    6 Tested up to: 5.2.0
    7 Stable tag: 1.1.2
     6Tested up to: 4.9
     7Stable tag: 1.1.3
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl.html
     
    4040* Google Maps
    4141
     42
     43= PLACEHOLDERS =
     44Several strategies to fill the area of an image before it loads.
     45
     46* **Keeping the space empty for the image:** In a world of responsive design, this prevents content from jumping around. Those layout changes are bad from a user’s experience point of view, but also for performance. The browser is forced to do layout re calculations every time it fetches the dimensions of an image, leaving space for it.
     47* **Placeholder:** Imagine that we are displaying a user’s profile image. We might want to display a silhouette in the background. This is shown while the main image is loaded, but also when that request failed or when the user didn’t set any profile picture at all. These images are usually vector-based, and due to their small size are a good candidate to be inlined.
     48* **Solid colour:** Take a colour from the image and use it as the background colour for the placeholder. This can be the dominant colour, the most vibrant… The idea is that it is based on the image you are loading and should help making the transition between no image to image loaded smoother.
     49* **Blurry image:** Also called blur-up technique. You render a tiny version of the image and then transition to the full one. The initial image is tiny both in pixels and kBs. To remove artifacts the image is scaled up and blurred.
     50
     51
    4252= PLUGIN COMPATIBILITY =
    4353* Work with any WordPress theme that follows the WordPress Theme Codex
     
    70802. Upload the 'easy-lazy-loader' folder to the '/wp-content/plugins/' directory,
    71813. Activate the plugin through the 'Plugins' menu in WordPress.
     82
     83For detailed documentation on how you can configure these options please visit the [Easy Lazy Loader](https://www.iprodev.com/easy-lazy-loader/) plugin page
    7284
    7385== Frequently Asked Questions ==
     
    102114== Changelog ==
    103115
     116= 1.1.3 =
     117
     118* **Optimized:** creating placeholder image.
     119
    104120= 1.1.2 =
    105121
Note: See TracChangeset for help on using the changeset viewer.