Last active
October 7, 2015 06:53
-
-
Save birgire/f17ecc6ad903a2c6b607 to your computer and use it in GitHub Desktop.
WordPress: Draft plugin solution the problem posted here http://wordpress.stackexchange.com/questions/204280/change-the-size-of-the-image-preview-on-the-media-edit-page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: Change the size of the Image preview on the media edit page | |
| * Author: Birgir Erlendsson (birgire) | |
| * Plugin URI: http://wordpress.stackexchange.com/questions/204280/change-the-size-of-the-image-preview-on-the-media-edit-page | |
| * | |
| * ------------------------------------------------------------------------------------ | |
| * Possible workaround, without core modifications, | |
| * but note that the javascript crop-selection numbers will not be accurate, | |
| * when $inf <> 400 | |
| * ------------------------------------------------------------------------------------ | |
| * Puzzle: It's interesting to note that the 'image_resize_dimensions' filter | |
| * doesn't get fired inside the 'wp_ajax_imgedit-preview' action | |
| * ------------------------------------------------------------------------------------ | |
| */ | |
| add_filter( 'admin_memory_limit', function( $limit ) | |
| { | |
| add_filter( 'image_resize_dimensions', function( $value, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) | |
| { | |
| if( | |
| ! did_action( 'wpse_resize_dimensions' ) | |
| && empty( $_REQUEST['history'] ) | |
| && ! empty( $_GET['action'] ) | |
| && 'imgedit-preview' === $_GET['action'] | |
| ) { | |
| do_action( 'wpse_resize_dimensions' ); | |
| $inf = 600; // <-- Default is 400 - Modify this too your needs! | |
| $ratio = wpse_image_get_preview_ratio( $orig_w, $orig_h, $inf ); | |
| $dest_w = max ( 1, $orig_w * $ratio ); | |
| $dest_h = max ( 1, $orig_h * $ratio ); | |
| return image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, $crop ); | |
| } | |
| return $value; | |
| }, 10, 6 ); | |
| return $limit; | |
| } ); | |
| /** | |
| * Our modified version of _image_get_preview_ratio() | |
| */ | |
| function wpse_image_get_preview_ratio($w, $h, $inf = 400 ) | |
| { | |
| $max = max( $w, $h ); | |
| return $max > $inf ? ($inf / $max) : 1; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment