PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.2.6
Gallery : FooGallery v3.2.6
3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / includes / class-retina.php
foogallery / includes Last commit date
abilities 4 weeks ago admin 4 weeks ago compatibility 4 weeks ago extensions 4 weeks ago foopluginbase 4 weeks ago public 4 weeks ago thumbs 4 weeks ago asset-manifest.php 4 weeks ago class-attachment-filters.php 4 weeks ago class-command-palette.php 4 weeks ago class-foogallery-animated-gif-support.php 4 weeks ago class-foogallery-attachment-custom-class.php 4 weeks ago class-foogallery-attachment-filename.php 4 weeks ago class-foogallery-attachment-type.php 4 weeks ago class-foogallery-attachment.php 4 weeks ago class-foogallery-cache.php 4 weeks ago class-foogallery-common-fields.php 4 weeks ago class-foogallery-crop-position.php 4 weeks ago class-foogallery-datasource-media_library.php 4 weeks ago class-foogallery-debug.php 4 weeks ago class-foogallery-delayed-runtime-loader.php 4 weeks ago class-foogallery-extensions-compatibility.php 4 weeks ago class-foogallery-force-https.php 4 weeks ago class-foogallery-lazyload.php 4 weeks ago class-foogallery-license-constant-handler.php 4 weeks ago class-foogallery-lightbox.php 4 weeks ago class-foogallery-paging.php 4 weeks ago class-foogallery-password-protect.php 4 weeks ago class-foogallery-sitemaps.php 4 weeks ago class-foogallery-widget.php 4 weeks ago class-foogallery.php 4 weeks ago class-gallery-advanced-settings.php 4 weeks ago class-il8n.php 4 weeks ago class-override-thumbnail.php 4 weeks ago class-posttypes.php 4 weeks ago class-previews.php 4 weeks ago class-retina.php 4 weeks ago class-thumbnail-dimensions.php 4 weeks ago class-thumbnails.php 4 weeks ago class-version-check.php 4 weeks ago constants.php 4 weeks ago functions.php 4 weeks ago gallery-management-functions.php 4 weeks ago includes.php 4 weeks ago index.php 4 weeks ago render-functions.php 4 weeks ago
class-retina.php
88 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /*
8 * FooGallery Retina Support class
9 */
10
11 if ( !class_exists( 'FooGallery_Retina' ) ) {
12
13 class FooGallery_Retina {
14
15 function __construct() {
16 add_filter('foogallery_attachment_html_image_attributes', array($this, 'add_retina_attributes'), 10, 3);
17 }
18
19 /**
20 * @param array $attr
21 * @param array $args
22 * @param FooGalleryAttachment $attachment
23 * @return mixed
24 */
25 function add_retina_attributes($attr, $args, $attachment) {
26 global $current_foogallery;
27
28 if ( $current_foogallery && $current_foogallery->gallery_template ) {
29
30 //first check if the gallery has saved Retina settings
31 if ( isset($current_foogallery->retina) && is_array( $current_foogallery->retina ) ) {
32 $srcset = array();
33
34 //get the original thumb dimensions
35 $original_thumb_width = array_key_exists( 'width', $args ) ? intval( $args['width'] ) : 0;
36 $original_thumb_height = array_key_exists( 'height', $args ) ? intval( $args['height'] ) : 0;
37
38 //get the original full size image dimensions
39 $original_width = $attachment->width;
40 $original_height = $attachment->height;
41
42 //if we do not have a width, we need to calculate one
43 if ( 0 === $original_thumb_width ) {
44 //find closest ratio multiple to image size
45 if( $original_width > $original_height ) {
46 //landscape
47 $ratio = $original_width / $original_height;
48 $original_thumb_width = intval( $original_thumb_height * $ratio );
49 }else{
50 //portrait
51 $ratio = $original_height / $original_width;
52 $original_thumb_width = intval( $original_thumb_height / $ratio );
53 }
54 }
55
56 foreach ( foogallery_retina_options() as $pixel_density ) {
57 $pixel_density_supported = array_key_exists( $pixel_density, $current_foogallery->retina ) ? ('true' === $current_foogallery->retina[$pixel_density]) : false;
58
59 if ( $pixel_density_supported ) {
60 $pixel_density_int = intval( str_replace( 'x', '', $pixel_density ) );
61
62 //apply scaling to the width and height attributes
63 $retina_width = $original_thumb_width * $pixel_density_int;
64 $retina_height = $original_thumb_height * $pixel_density_int;
65
66 //if the new dimensions are smaller than the full size image dimensions then allow the retina thumb
67 if ( $retina_width < $original_width &&
68 $retina_height < $original_height ) {
69 $args['width'] = $retina_width;
70 $args['height'] = $retina_height;
71
72 //build up the retina attributes
73 $srcset[] = $attachment->html_img_src( $args ) . ' ' . $pixel_density_int . 'x';
74 }
75 }
76 }
77
78 if ( count( $srcset ) ) {
79 $attr['srcset'] = implode( ',', $srcset );
80 }
81 }
82 }
83
84 return $attr;
85 }
86 }
87 }
88