Changeset 2064930
- Timestamp:
- 04/08/2019 09:34:42 AM (7 years ago)
- Location:
- easy-lazy-loader/trunk
- Files:
-
- 2 edited
-
easy-lazy-loader.php (modified) (6 diffs)
-
readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
easy-lazy-loader/trunk/easy-lazy-loader.php
r1747658 r2064930 2 2 /* 3 3 Plugin Name: Easy Lazy Loader 4 Version: 1.1. 25 Plugin URI: https://www.iprodev.com/ go/easy-lazy-loader/4 Version: 1.1.3 5 Plugin URI: https://www.iprodev.com/easy-lazy-loader/ 6 6 Author: iProDev 7 7 Author URI: https://www.iprodev.com/ … … 619 619 // don't to the replacement if the image is a data-uri 620 620 if ( ! preg_match( "/src=['\"]data:image/is", $imgHTML ) ) { 621 622 if ( 'color' === $placeholder_type && ( !class_exists( 'WordPress_Gallery_Extra' ) ) ) { 623 $placeholder_type = 'default'; 624 } 621 625 622 626 $placeholder_url_used = $placeholder_url; … … 635 639 } 636 640 // use color as placeholder if applicable 637 else if ( 'color' === $placeholder_type && class_exists( 'WordPress_Gallery_Extra' )) {641 else if ( 'color' === $placeholder_type ) { 638 642 $placeholder_color = ""; 639 643 … … 939 943 * @return string The placeholder datauri 940 944 */ 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 = "" ) { 942 946 if ( $width >= 30 && $height >= 30 ) { 943 947 $new_dimensions = wp_constrain_dimensions( $width, $height, 30, 30 ); … … 955 959 } 956 960 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 ); 967 1005 } 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 } 995 1008 } 996 1009 … … 1020 1033 1021 1034 $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 1022 1042 $image_src = preg_replace( "/-[0-9]+x[0-9]+./i", '.', $image_src ); 1023 1043 $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 === 2 2 Contributors: iprodev 3 Donate link: https:// iprodev.com/easy-lazy-loader3 Donate link: https://www.iprodev.com/easy-lazy-loader 4 4 Tags: lazy load, images, videos, audios, iframes, front-end optimization 5 5 Requires at least: 3.2 6 Tested up to: 5.2.07 Stable tag: 1.1. 26 Tested up to: 4.9 7 Stable tag: 1.1.3 8 8 License: GPLv3 9 9 License URI: https://www.gnu.org/licenses/gpl.html … … 40 40 * Google Maps 41 41 42 43 = PLACEHOLDERS = 44 Several 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 42 52 = PLUGIN COMPATIBILITY = 43 53 * Work with any WordPress theme that follows the WordPress Theme Codex … … 70 80 2. Upload the 'easy-lazy-loader' folder to the '/wp-content/plugins/' directory, 71 81 3. Activate the plugin through the 'Plugins' menu in WordPress. 82 83 For detailed documentation on how you can configure these options please visit the [Easy Lazy Loader](https://www.iprodev.com/easy-lazy-loader/) plugin page 72 84 73 85 == Frequently Asked Questions == … … 102 114 == Changelog == 103 115 116 = 1.1.3 = 117 118 * **Optimized:** creating placeholder image. 119 104 120 = 1.1.2 = 105 121
Note: See TracChangeset
for help on using the changeset viewer.