Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions high-resoloution-images-with-srcset.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ function __construct() {
add_filter( 'image_send_to_editor', array( $this, 'image_send_to_editor' ), 100, 8 );
add_filter( 'tiny_mce_before_init', array( $this, 'modify_mce_options' ), 100 );

if ( defined( 'HM_WP_SRCSET_ADD_2X_IMAGE_SIZES' ) && HM_WP_SRCSET_ADD_2X_IMAGE_SIZES ) {
$this->add_2x_image_sizes();
}

}

/**
Expand All @@ -66,7 +70,7 @@ function plugin_activation_check() {
*/
function enqueue_scripts() {

wp_enqueue_script( 'picturefill', $this->plugin_url . '/picturefill/dist/picturefill.min.js', false, false, true );
wp_enqueue_script( 'picturefill', $this->plugin_url . 'picturefill/dist/picturefill.min.js', false, false, true );

}

Expand Down Expand Up @@ -103,8 +107,10 @@ function image_downsize( $null, $attachment_id, $size ) {
}
}

$attr['src'] = $requested_image[0];
$attr['srcset'] = implode( ', ', $srcset );
if ( ! empty( $srcset ) ) {
$attr['src'] = $requested_image[0];
$attr['srcset'] = implode( ', ', $srcset );
}

add_filter( 'image_downsize', array( $that, 'image_downsize' ), 100, 3 );

Expand Down Expand Up @@ -219,6 +225,27 @@ function modify_mce_options( Array $init ) {

}

function add_2x_image_sizes() {
global $_wp_additional_image_sizes;
foreach ( get_intermediate_image_sizes() as $size ) {

if ( in_array( $size, array( 'thumbnail', 'medium', 'large' ) ) ) {
$args = array(
'width' => get_option( 'thumbnail_size_w' ),
'height' => get_option( 'thumbnail_size_h' ),
'crop' => get_option( 'thumbnail_size_crop' )
);
} elseif ( isset( $_wp_additional_image_sizes[ $size ] ) ) {
$args = $_wp_additional_image_sizes[ $size ];
} else {
continue;
}

add_image_size( $size . '2x', $args['width'] * 2, $args['height'] * 2, $args['crop'] );

}
}

}

$retina = new HM_WP_Srcset();