├── images └── ajax-loader.gif ├── languages ├── imsanity-es_MX.mo ├── imsanity-sv_SE.mo ├── readme.txt ├── imsanity-sv_SE.po └── imsanity-es_MX.po ├── .travis.yml ├── phpcs.ruleset.xml ├── class-imsanity-cli.php ├── ajax.php ├── scripts └── imsanity.js ├── media.php ├── changelog.txt ├── README.md ├── readme.txt ├── imsanity.php ├── libs └── utils.php ├── settings.php └── license.txt /images/ajax-loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nosilver4u/imsanity/HEAD/images/ajax-loader.gif -------------------------------------------------------------------------------- /languages/imsanity-es_MX.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nosilver4u/imsanity/HEAD/languages/imsanity-es_MX.mo -------------------------------------------------------------------------------- /languages/imsanity-sv_SE.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nosilver4u/imsanity/HEAD/languages/imsanity-sv_SE.mo -------------------------------------------------------------------------------- /languages/readme.txt: -------------------------------------------------------------------------------- 1 | LANGUAGE TRANSLATION FILES FOR IMSANITY 2 | --------------------------------------- 3 | 4 | If you are interested in creating a language translation for Imsanity then 5 | you're in the right place! We would love your help, and you 6 | can get started translating Imsanity at https://translate.wordpress.org/projects/wp-plugins/imsanity 7 | 8 | Anything you can do to help is greatly appreciated and allows 9 | Imsanity to be more easily used by people all over the world. 10 | 11 | Thank you for supporting Imsanity and all free software! 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | os: linux 2 | 3 | dist: bionic 4 | 5 | language: php 6 | 7 | notifications: 8 | email: 9 | on_success: never 10 | on_failure: change 11 | 12 | branches: 13 | only: 14 | - master 15 | 16 | php: 17 | - 7.4 18 | - 8.3 19 | 20 | env: 21 | - WP_VERSION=latest WP_MULTISITE=0 22 | 23 | before_script: 24 | - export PATH="$HOME/.config/composer/vendor/bin:$PATH" 25 | - phpenv config-rm xdebug.ini 26 | - composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true 27 | - composer global require --dev wp-coding-standards/wpcs phpcompatibility/phpcompatibility-wp 28 | 29 | script: 30 | - phpcs --standard=phpcs.ruleset.xml --extensions=php . 31 | -------------------------------------------------------------------------------- /phpcs.ruleset.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Generally-applicable sniffs for WordPress plugins 4 | 5 | */vendor/* 6 | */tests/* 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 7.4- 19 | 20 | 10 21 | 22 | 23 | 24 | 10 25 | 26 | 27 | 28 | 10 29 | 30 | 31 | -------------------------------------------------------------------------------- /class-imsanity-cli.php: -------------------------------------------------------------------------------- 1 | 23 | * : do not prompt, just resize everything 24 | * 25 | * ## EXAMPLES 26 | * 27 | * wp-cli imsanity resize --noprompt 28 | * 29 | * @synopsis [--noprompt] 30 | * 31 | * @param array $args A numbered array of arguments provided via WP-CLI without option names. 32 | * @param array $assoc_args An array of named arguments provided via WP-CLI. 33 | */ 34 | public function resize( $args, $assoc_args ) { 35 | 36 | // let's get started, shall we? 37 | // imsanity_init();. 38 | $maxw = imsanity_get_option( 'imsanity_max_width', IMSANITY_DEFAULT_MAX_WIDTH ); 39 | $maxh = imsanity_get_option( 'imsanity_max_height', IMSANITY_DEFAULT_MAX_HEIGHT ); 40 | 41 | if ( empty( $assoc_args['noprompt'] ) ) { 42 | WP_CLI::warning( 43 | __( 'Bulk Resize will alter your original images and cannot be undone!', 'imsanity' ) . "\n" . 44 | __( 'It is HIGHLY recommended that you backup your wp-content/uploads folder before proceeding. You will be prompted before resizing each image.', 'imsanity' ) . "\n" . 45 | __( 'It is also recommended that you initially resize only 1 or 2 images and verify that everything is working properly before processing your entire library.', 'imsanity' ) 46 | ); 47 | } 48 | 49 | /* translators: 1: width in pixels, 2: height in pixels */ 50 | WP_CLI::line( sprintf( __( 'Resizing images to %1$d x %2$d', 'imsanity' ), $maxw, $maxh ) ); 51 | 52 | global $wpdb; 53 | $attachments = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE (post_type = 'attachment' OR post_type = 'ims_image') AND post_mime_type LIKE '%%image%%' ORDER BY ID DESC" ); 54 | 55 | $image_count = count( $attachments ); 56 | if ( ! $image_count ) { 57 | WP_CLI::success( __( 'There are no images to resize.', 'imsanity' ) ); 58 | return; 59 | } elseif ( empty( $assoc_args['noprompt'] ) ) { 60 | WP_CLI::confirm( 61 | /* translators: %d: number of images */ 62 | sprintf( __( 'There are %d images to check.', 'imsanity' ), $image_count ) . 63 | ' ' . __( 'Continue?', 'imsanity' ) 64 | ); 65 | } else { 66 | /* translators: %d: number of images */ 67 | WP_CLI::line( sprintf( __( 'There are %d images to check.', 'imsanity' ), $image_count ) ); 68 | } 69 | 70 | $images_finished = 0; 71 | foreach ( $attachments as $id ) { 72 | $imagew = false; 73 | $imageh = false; 74 | ++$images_finished; 75 | 76 | $path = get_attached_file( $id ); 77 | if ( $path ) { 78 | list( $imagew, $imageh ) = getimagesize( $path ); 79 | } 80 | if ( empty( $imagew ) || empty( $imageh ) ) { 81 | continue; 82 | } 83 | 84 | if ( $imagew <= $maxw && $imageh <= $maxh ) { 85 | /* translators: %s: File-name of the image */ 86 | WP_CLI::line( sprintf( esc_html__( 'SKIPPED: %s (Resize not required)', 'imsanity' ), $path ) . " -- $imagew x $imageh" ); 87 | continue; 88 | } 89 | 90 | $confirm = ''; 91 | if ( empty( $assoc_args['noprompt'] ) ) { 92 | $confirm = \cli\prompt( 93 | $path . ': ' . $imagew . 'x' . $imageh . 94 | "\n" . __( 'Resize (Y/n)?', 'imsanity' ) 95 | ); 96 | } 97 | if ( 'n' === $confirm ) { 98 | continue; 99 | } 100 | 101 | $result = imsanity_resize_from_id( $id ); 102 | 103 | if ( $result['success'] ) { 104 | WP_CLI::line( $result['message'] . " $images_finished / $image_count" ); 105 | } else { 106 | WP_CLI::warning( $result['message'] . " $images_finished / $image_count" ); 107 | } 108 | } 109 | 110 | // and let the user know we are done. 111 | WP_CLI::success( __( 'Finished Resizing!', 'imsanity' ) ); 112 | } 113 | } 114 | 115 | WP_CLI::add_command( 'imsanity', 'Imsanity_CLI' ); 116 | -------------------------------------------------------------------------------- /ajax.php: -------------------------------------------------------------------------------- 1 | false, 23 | 'message' => esc_html__( 'Administrator permission is required', 'imsanity' ), 24 | ) 25 | ); 26 | } 27 | if ( ! wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'imsanity-bulk' ) && ! wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'imsanity-manual-resize' ) ) { 28 | wp_send_json( 29 | array( 30 | 'success' => false, 31 | 'message' => esc_html__( 'Access token has expired, please reload the page.', 'imsanity' ), 32 | ) 33 | ); 34 | } 35 | 36 | $resume_id = ! empty( $_POST['resume_id'] ) ? (int) $_POST['resume_id'] : PHP_INT_MAX; 37 | global $wpdb; 38 | // Load up all the image attachments we can find. 39 | $attachments = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE ID < %d AND post_type = 'attachment' AND post_mime_type LIKE %s ORDER BY ID DESC", $resume_id, '%%image%%' ) ); 40 | array_walk( $attachments, 'intval' ); 41 | wp_send_json( $attachments ); 42 | } 43 | 44 | /** 45 | * Resizes the image with the given id according to the configured max width and height settings 46 | * renders a json response indicating success/failure and dies. 47 | */ 48 | function imsanity_ajax_resize() { 49 | $permissions = apply_filters( 'imsanity_editor_permissions', 'edit_others_posts' ); 50 | if ( ! current_user_can( $permissions ) || empty( $_REQUEST['_wpnonce'] ) ) { 51 | wp_send_json( 52 | array( 53 | 'success' => false, 54 | 'message' => esc_html__( 'Editor permission is required', 'imsanity' ), 55 | ) 56 | ); 57 | } 58 | if ( ! wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'imsanity-bulk' ) && ! wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'imsanity-manual-resize' ) ) { 59 | wp_send_json( 60 | array( 61 | 'success' => false, 62 | 'message' => esc_html__( 'Access token has expired, please reload the page.', 'imsanity' ), 63 | ) 64 | ); 65 | } 66 | 67 | $id = ! empty( $_POST['id'] ) ? (int) $_POST['id'] : 0; 68 | if ( ! $id ) { 69 | wp_send_json( 70 | array( 71 | 'success' => false, 72 | 'message' => esc_html__( 'Missing ID Parameter', 'imsanity' ), 73 | ) 74 | ); 75 | } 76 | $results = imsanity_resize_from_id( $id ); 77 | if ( ! empty( $_POST['resumable'] ) ) { 78 | update_option( 'imsanity_resume_id', $id, false ); 79 | sleep( 1 ); 80 | } 81 | 82 | wp_send_json( $results ); 83 | } 84 | 85 | /** 86 | * Removes the original image with the given id and renders a json response indicating success/failure and dies. 87 | */ 88 | function imsanity_ajax_remove_original() { 89 | $permissions = apply_filters( 'imsanity_editor_permissions', 'edit_others_posts' ); 90 | if ( ! current_user_can( $permissions ) || empty( $_REQUEST['_wpnonce'] ) ) { 91 | wp_send_json( 92 | array( 93 | 'success' => false, 94 | 'message' => esc_html__( 'Editor permission is required', 'imsanity' ), 95 | ) 96 | ); 97 | } 98 | if ( ! wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'imsanity-bulk' ) && ! wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'imsanity-manual-resize' ) ) { 99 | wp_send_json( 100 | array( 101 | 'success' => false, 102 | 'message' => esc_html__( 'Access token has expired, please reload the page.', 'imsanity' ), 103 | ) 104 | ); 105 | } 106 | 107 | $id = ! empty( $_POST['id'] ) ? (int) $_POST['id'] : 0; 108 | if ( ! $id ) { 109 | wp_send_json( 110 | array( 111 | 'success' => false, 112 | 'message' => esc_html__( 'Missing ID Parameter', 'imsanity' ), 113 | ) 114 | ); 115 | } 116 | $remove_original = imsanity_remove_original_image( $id ); 117 | if ( $remove_original && is_array( $remove_original ) ) { 118 | wp_update_attachment_metadata( $id, $remove_original ); 119 | wp_send_json( array( 'success' => true ) ); 120 | } 121 | 122 | wp_send_json( array( 'success' => false ) ); 123 | } 124 | 125 | /** 126 | * Finalizes the resizing process. 127 | */ 128 | function imsanity_ajax_finish() { 129 | $permissions = apply_filters( 'imsanity_admin_permissions', 'manage_options' ); 130 | if ( ! current_user_can( $permissions ) || empty( $_REQUEST['_wpnonce'] ) ) { 131 | wp_send_json( 132 | array( 133 | 'success' => false, 134 | 'message' => esc_html__( 'Administrator permission is required', 'imsanity' ), 135 | ) 136 | ); 137 | } 138 | if ( ! wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'imsanity-bulk' ) && ! wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'imsanity-manual-resize' ) ) { 139 | wp_send_json( 140 | array( 141 | 'success' => false, 142 | 'message' => esc_html__( 'Access token has expired, please reload the page.', 'imsanity' ), 143 | ) 144 | ); 145 | } 146 | 147 | update_option( 'imsanity_resume_id', 0, false ); 148 | 149 | die(); 150 | } 151 | -------------------------------------------------------------------------------- /scripts/imsanity.js: -------------------------------------------------------------------------------- 1 | /** 2 | * imsanity admin javascript functions 3 | */ 4 | 5 | jQuery(document).ready(function($) {$(".fade").fadeTo(5000,1).fadeOut(3000);}); 6 | 7 | // Handle a manual resize from the media library. 8 | jQuery(document).on('click', '.imsanity-manual-resize', function() { 9 | var post_id = jQuery(this).data('id'); 10 | var imsanity_nonce = jQuery(this).data('nonce'); 11 | jQuery('#imsanity-media-status-' + post_id ).html( imsanity_vars.resizing ); 12 | jQuery.post( 13 | ajaxurl, 14 | {_wpnonce: imsanity_nonce, action: 'imsanity_resize_image', id: post_id}, 15 | function(response) { 16 | var target = jQuery('#imsanity-media-status-' + post_id ); 17 | try { 18 | target.html(response.message); 19 | } catch(e) { 20 | target.html(imsanity_vars.invalid_response); 21 | if (console) { 22 | console.warn(post_id + ': '+ e.message); 23 | console.warn('Invalid JSON Response: ' + JSON.stringify(response)); 24 | } 25 | } 26 | } 27 | ); 28 | return false; 29 | }); 30 | 31 | // Handle an original image removal request from the media library. 32 | jQuery(document).on('click', '.imsanity-manual-remove-original', function() { 33 | var post_id = jQuery(this).data('id'); 34 | var imsanity_nonce = jQuery(this).data('nonce'); 35 | jQuery('#imsanity-media-status-' + post_id ).html( imsanity_vars.resizing ); 36 | jQuery.post( 37 | ajaxurl, 38 | {_wpnonce: imsanity_nonce, action: 'imsanity_remove_original', id: post_id}, 39 | function(response) { 40 | var target = jQuery('#imsanity-media-status-' + post_id ); 41 | try { 42 | if (! response.success) { 43 | target.html(imsanity_vars.removal_failed); 44 | } else { 45 | target.html(imsanity_vars.removal_succeeded); 46 | } 47 | } catch(e) { 48 | target.html(imsanity_vars.invalid_response); 49 | if (console) { 50 | console.warn(post_id + ': '+ e.message); 51 | console.warn('Invalid JSON Response: ' + JSON.stringify(response)); 52 | } 53 | } 54 | } 55 | ); 56 | return false; 57 | }); 58 | 59 | jQuery(document).on('submit', '#imsanity-bulk-stop', function() { 60 | jQuery(this).hide(); 61 | imsanity_vars.stopped = true; 62 | imsanity_vars.attachments = []; 63 | jQuery('#imsanity_loading').html(imsanity_vars.operation_stopped); 64 | jQuery('#imsanity_loading').show(); 65 | return false; 66 | }); 67 | 68 | /** 69 | * Begin the process of re-sizing all of the checked images 70 | */ 71 | function imsanity_resize_images() { 72 | // start the recursion 73 | imsanity_resize_next(0); 74 | } 75 | 76 | /** 77 | * recursive function for resizing images 78 | */ 79 | function imsanity_resize_next(next_index) { 80 | if (next_index >= imsanity_vars.attachments.length) return imsanity_resize_complete(); 81 | var total_images = imsanity_vars.attachments.length; 82 | var target = jQuery('#resize_results'); 83 | target.show(); 84 | 85 | jQuery.post( 86 | ajaxurl, // (defined by wordpress - points to admin-ajax.php) 87 | {_wpnonce: imsanity_vars._wpnonce, action: 'imsanity_resize_image', id: imsanity_vars.attachments[next_index], resumable: 1}, 88 | function (response) { 89 | var result; 90 | jQuery('#bulk-resize-beginning').hide(); 91 | 92 | try { 93 | target.append('
' + (next_index+1) + '/' + total_images + ' >> ' + response.message +'
'); 94 | } catch(e) { 95 | target.append('
' + imsanity_vars.invalid_response + '
'); 96 | if (console) { 97 | console.warn(imsanity_vars.attachments[next_index] + ': '+ e.message); 98 | console.warn('Invalid JSON Response: ' + JSON.stringify(response)); 99 | } 100 | } 101 | // recurse 102 | imsanity_resize_next(next_index+1); 103 | } 104 | ); 105 | } 106 | 107 | /** 108 | * fired when all images have been resized 109 | */ 110 | function imsanity_resize_complete() { 111 | var target = jQuery('#resize_results'); 112 | if (! imsanity_vars.stopped) { 113 | jQuery('#imsanity-bulk-stop').hide(); 114 | target.append('
' + imsanity_vars.resizing_complete + '
'); 115 | jQuery.post( 116 | ajaxurl, // (global defined by wordpress - points to admin-ajax.php) 117 | {_wpnonce: imsanity_vars._wpnonce, action: 'imsanity_bulk_complete'} 118 | ); 119 | } 120 | } 121 | 122 | /** 123 | * ajax post to return all images from the library 124 | * @param string the id of the html element into which results will be appended 125 | */ 126 | function imsanity_load_images() { 127 | var imsanity_really_resize_all = confirm(imsanity_vars.resize_all_prompt); 128 | if ( ! imsanity_really_resize_all ) { 129 | return; 130 | } 131 | jQuery('#imsanity-examine-button').hide(); 132 | jQuery('.imsanity-bulk-text').hide(); 133 | jQuery('#imsanity-bulk-reset').hide(); 134 | jQuery('#imsanity_loading').show(); 135 | 136 | jQuery.post( 137 | ajaxurl, // (global defined by wordpress - points to admin-ajax.php) 138 | {_wpnonce: imsanity_vars._wpnonce, action: 'imsanity_get_images', resume_id: imsanity_vars.resume_id}, 139 | function(response) { 140 | var images = response; 141 | if (! Array.isArray(images)) { 142 | console.log( response ); 143 | return false; 144 | } 145 | 146 | jQuery('#imsanity_loading').hide(); 147 | if (images.length > 0) { 148 | imsanity_vars.attachments = images; 149 | imsanity_vars.stopped = false; 150 | jQuery('#imsanity-bulk-stop').show(); 151 | imsanity_resize_images(); 152 | } else { 153 | jQuery('#imsanity_loading').html('
' + imsanity_vars.none_found + '
'); 154 | } 155 | } 156 | ); 157 | } 158 | -------------------------------------------------------------------------------- /media.php: -------------------------------------------------------------------------------- 1 | '; 35 | if ( false && function_exists( 'print_r' ) ) { 36 | $print_meta = print_r( $meta, true ); 37 | $print_meta = preg_replace( array( '/ /', '/\n+/' ), array( ' ', '
' ), $print_meta ); 38 | echo "
" . wp_kses_post( $print_meta ) . '
'; 39 | } 40 | if ( is_array( $meta ) && ! empty( $meta['file'] ) && false !== strpos( $meta['file'], 'https://images-na.ssl-images-amazon.com' ) ) { 41 | echo esc_html__( 'Amazon-hosted image', 'imsanity' ) . ''; 42 | return; 43 | } 44 | if ( is_array( $meta ) && ! empty( $meta['cloudinary'] ) ) { 45 | echo esc_html__( 'Cloudinary image', 'imsanity' ) . ''; 46 | return; 47 | } 48 | if ( is_array( $meta ) & class_exists( 'WindowsAzureStorageUtil' ) && ! empty( $meta['url'] ) ) { 49 | echo '
' . esc_html__( 'Azure Storage image', 'imsanity' ) . '
'; 50 | return; 51 | } 52 | if ( is_array( $meta ) && class_exists( 'Amazon_S3_And_CloudFront' ) && preg_match( '/^(http|s3|gs)\w*:/', get_attached_file( $id ) ) ) { 53 | echo '
' . esc_html__( 'Offloaded Media', 'imsanity' ) . '
'; 54 | return; 55 | } 56 | if ( is_array( $meta ) && class_exists( 'S3_Uploads' ) && preg_match( '/^(http|s3|gs)\w*:/', get_attached_file( $id ) ) ) { 57 | echo '
' . esc_html__( 'Amazon S3 image', 'imsanity' ) . '
'; 58 | return; 59 | } 60 | if ( is_array( $meta ) & class_exists( 'wpCloud\StatelessMedia' ) && ! empty( $meta['gs_link'] ) ) { 61 | echo '
' . esc_html__( 'WP Stateless image', 'imsanity' ) . '
'; 62 | return; 63 | } 64 | $file_path = imsanity_attachment_path( $meta, $id ); 65 | if ( is_array( $meta ) & function_exists( 'ilab_get_image_sizes' ) && ! empty( $meta['s3'] ) && empty( $file_path ) ) { 66 | echo esc_html__( 'Media Cloud image', 'imsanity' ) . ''; 67 | return; 68 | } 69 | // If the file does not exist. 70 | if ( empty( $file_path ) ) { 71 | echo esc_html__( 'Could not retrieve file path.', 'imsanity' ) . ''; 72 | return; 73 | } 74 | // Let folks filter the allowed mime-types for resizing. 75 | $allowed_types = apply_filters( 'imsanity_allowed_mimes', array( 'image/png', 'image/gif', 'image/jpeg' ), $file_path ); 76 | if ( is_string( $allowed_types ) ) { 77 | $allowed_types = array( $allowed_types ); 78 | } elseif ( ! is_array( $allowed_types ) ) { 79 | $allowed_types = array(); 80 | } 81 | $ftype = imsanity_quick_mimetype( $file_path ); 82 | if ( ! in_array( $ftype, $allowed_types, true ) ) { 83 | echo ''; 84 | return; 85 | } 86 | 87 | list( $imagew, $imageh ) = getimagesize( $file_path ); 88 | if ( empty( $imagew ) || empty( $imageh ) ) { 89 | $imagew = $meta['width']; 90 | $imageh = $meta['height']; 91 | } 92 | 93 | if ( empty( $imagew ) || empty( $imageh ) ) { 94 | echo esc_html( 'Unknown dimensions', 'imsanity' ); 95 | return; 96 | } 97 | echo '
' . (int) $imagew . 'w x ' . (int) $imageh . 'h
'; 98 | 99 | $maxw = imsanity_get_option( 'imsanity_max_width', IMSANITY_DEFAULT_MAX_WIDTH ); 100 | $maxh = imsanity_get_option( 'imsanity_max_height', IMSANITY_DEFAULT_MAX_HEIGHT ); 101 | $permissions = apply_filters( 'imsanity_editor_permissions', 'edit_others_posts' ); 102 | if ( $imagew > $maxw || $imageh > $maxh ) { 103 | if ( current_user_can( $permissions ) ) { 104 | $manual_nonce = wp_create_nonce( 'imsanity-manual-resize' ); 105 | // Give the user the option to optimize the image right now. 106 | printf( 107 | '
', 108 | (int) $id, 109 | esc_attr( $manual_nonce ), 110 | esc_html__( 'Resize Image', 'imsanity' ) 111 | ); 112 | } 113 | } elseif ( current_user_can( $permissions ) && imsanity_get_option( 'imsanity_delete_originals', false ) && ! empty( $meta['original_image'] ) && function_exists( 'wp_get_original_image_path' ) ) { 114 | $original_image = wp_get_original_image_path( $id ); 115 | if ( empty( $original_image ) || ! is_file( $original_image ) ) { 116 | $original_image = wp_get_original_image_path( $id, true ); 117 | } 118 | if ( ! empty( $original_image ) && is_file( $original_image ) && is_writable( $original_image ) ) { 119 | $link_text = __( 'Remove Original', 'imsanity' ); 120 | } else { 121 | $link_text = __( 'Remove Original Link', 'imsanity' ); 122 | } 123 | $manual_nonce = wp_create_nonce( 'imsanity-manual-resize' ); 124 | // Give the user the option to optimize the image right now. 125 | printf( 126 | '
', 127 | (int) $id, 128 | esc_attr( $manual_nonce ), 129 | esc_html( $link_text ) 130 | ); 131 | } 132 | echo '
'; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /changelog.txt: -------------------------------------------------------------------------------- 1 | = 2.8.7 = 2 | *Release Date = August 6, 2024* 3 | 4 | * added: change default permissions via imsanity_editor_permissions and imsanity_admin_permissions filters 5 | * changed: default permission to resize individual images changed to editor role 6 | 7 | = 2.8.6 = 8 | *Release Date - November 26, 2024* 9 | 10 | * fixed: fatal error if other plugins run big_image_size_threshold filter with too few arguments 11 | 12 | = 2.8.5 = 13 | *Release Date – November 26, 2024* 14 | 15 | * bumped WP tested version 16 | * changed: improve JSON handling/efficiency 17 | 18 | = 2.8.4 = 19 | *Release Date – April 29, 2024* 20 | 21 | * bumped WP tested version and PHP minimum 22 | 23 | = 2.8.3 = 24 | *Release Date – April 23, 2024* 25 | 26 | * changed: use updated WP coding standards 27 | * fixed: PHP 8 error trying to do math with string values 28 | 29 | = 2.8.2 = 30 | *Release Date – October 5, 2022* 31 | 32 | * fixed: mime type error when filename in attachment metadata is incorrect 33 | 34 | = 2.8.1 = 35 | *Release Date – June 16, 2022* 36 | 37 | * changed: escape and sanitize more things 38 | * changed: tighten PHPCS rules used for pre-release testing 39 | 40 | = 2.8.0 = 41 | *Release Date – May 18, 2022* 42 | 43 | * added: support for resizing WebP images via ImageMagick 44 | * changed: update attachment file size to keep WP 6.0 metadata in sync 45 | * changed: use original image for resizing if full size version was scaled by WordPress 46 | * fixed: JS scroller during bulk resize causes unexpected behavior 47 | 48 | = 2.7.2 = 49 | *Release Date – June 3, 2021* 50 | 51 | * fixed: delete originals might remove full-size version in rare cases 52 | * fixed: error thrown for image that is 1 pixel larger than max dimensions 53 | 54 | = 2.7.1 = 55 | *Release Date – November 24, 2020* 56 | 57 | * changed: clarify text for queue reset button 58 | * changed: Delete Originals function in bulk/selective resizer will clean metadata if original image is already gone 59 | 60 | = 2.7.0 = 61 | *Release Date – November 18, 2020* 62 | 63 | * changed: bulk resizer will resize all images with no limits, use list mode for selective resizing 64 | * added: see current dimensions and resize individual images in Media Library list mode 65 | * added: imsanity_disable_convert filter to bypass BMP/PNG to JPG conversion options conditionally 66 | * added: imsanity_skip_image filter to bypass resizing programmatically 67 | * added: ability to remove pre-scaled original image backup (in bulk or selectively) 68 | * changed: PNG images will not be converted if transparency is found 69 | * fixed: BMP files not converted when server uses image/x-ms-bmp as mime identifier 70 | * removed: Deep Scan option is the default behavior now, no need for configuration 71 | 72 | = 2.6.1 = 73 | * fixed: wrong parameter passed to imsanity_attachment_path() 74 | 75 | = 2.6.0 = 76 | * added: wp-cli command 'wp help imsanity resize' 77 | * fixed: adding an image to a post in pre-draft status uses wrong settings/dimensions 78 | 79 | = 2.5.0 = 80 | * added: imsanity_allowed_mimes filter to override the default list of image formats allowed 81 | * added: imsanity_orientation filter to modify auto-rotation behavior, return 1 to bypass 82 | * added: imsanity_get_max_width_height filter to customize max width/height 83 | * added: define network settings as defaults for new sites in multi-site mode 84 | * fixed: WP threshold of 2560 overrides Imsanity when using larger dimensions 85 | * fixed: settings link on plugins page broken in some cases 86 | * fixed: crop filter not applied if max width or height is equal to existing dimension 87 | * fixed: invalid capabilities used for settings page - props @cfoellmann 88 | 89 | = 2.4.3 = 90 | * changed: default size from 2048 to 1920 91 | * fixed: WP Import plugin breaks during Media imports 92 | * fixed: setting a value to 0 causes errors on multi-site installs 93 | * fixed: conversion settings not displaying correctly on multi-site 94 | 95 | = 2.4.2 = 96 | * changed: noresize in filename also works in batch processing 97 | * fixed: error message does not contain filename when file is missing 98 | * fixed: notice on network settings when deep scan option has not been set before 99 | 100 | = 2.4.1 = 101 | * fixed: bulk resizer scan returning incorrect results 102 | * fixed: sprintf error during resizing and upload 103 | 104 | = 2.4.0 = 105 | * added: deep scanning option for when attachment metadata isn't updating properly 106 | * fixed: uploads from Gutenberg not detected properly 107 | * fixed: some other plugin(s) trying to muck with the Imsanity settings links and breaking things 108 | * fixed: undefined notice for query during ajax operation 109 | * fixed: stale metadata could prevent further resizing 110 | 111 | = 2.3.9 = 112 | * fixed: PNG to JPG filled transparency with black instead of white 113 | * fixed: auto-rotation causes incorrect scaling 114 | * fixed: results box stops scrolling at line 28 115 | * added: pre-emptive checks on file parameter to prevent read errors with getimagesize() 116 | 117 | = 2.3.8 = 118 | * added: 'imsanity_crop_image' filter to crop images during resizing 119 | * added: increased security of network settings and AJAX requests 120 | * changed: metadata fetch and update use correct functions instead of direct database queries 121 | * changed: bulk resize search is kinder to your database 122 | * fixed: bulk resize could produce a larger image 123 | * fixed: image file permissions not checked prior to resizing 124 | * fixed: EWWW Image Optimizer optimizes image during resizing instead of waiting for metadata generation 125 | * fixed: JPG quality not displaying correctly on network/multisite settings page 126 | * fixed: some strings were not translatable 127 | * fixed: bulk resize results container was not scrollable 128 | * removed: legacy resize function for WP lower than 3.5 129 | 130 | = 2.3.7 = 131 | * fixed: uploads to Media Library not detected properly 132 | * changed: default JPG quality is now 82, to match the WordPress default 133 | * changed: fr_FR and ru_RU moved to WP.org language packs 134 | * changed: new maintainer 135 | 136 | = 2.3.6 = 137 | * tested up to WP 4.4 138 | * if resized image is not smaller than original, then keep original 139 | * allow IMSANITY_AJAX_MAX_RECORDS to be overridden in wp-config.php 140 | * if png-to-jpg is enabled, replace png transparency with white 141 | 142 | = 2.3.5 = 143 | * Add option to hide Imsanity girl logo image on settings screen 144 | 145 | = 2.3.4 = 146 | * Security update to network settings page 147 | 148 | = 2.3.3 = 149 | * Update default size from 1024 to 2048 150 | * Tested up to WordPress 4.1.1 151 | * Move screenshots to /assets folder 152 | * Added 256x256 icon 153 | 154 | = 2.3.2 = 155 | * Add PNG-To-JPG Option thanks to Jody Nesbitt 156 | 157 | = 2.3.1 = 158 | * ignore errors if EXIF data is not readable 159 | * show counter when bulk resizing images 160 | 161 | = 2.3.0 = 162 | * fix for incorrectly identifying media uploads as coming from 'other' on WP 4+ 163 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Imsanity 2 | 3 | [![WordPress Plugin Downloads](https://img.shields.io/wordpress/plugin/dt/imsanity.svg)](https://wordpress.org/plugins/imsanity/) 4 | [![WordPress Plugin Rating](https://img.shields.io/wordpress/plugin/r/imsanity.svg)](https://wordpress.org/support/plugin/imsanity/reviews/) 5 | [![WordPress Plugin Version](https://img.shields.io/wordpress/plugin/v/imsanity.svg)](https://wordpress.org/plugins/imsanity/) 6 | [![WordPress Tested Up To](https://img.shields.io/wordpress/v/imsanity.svg)](https://wordpress.org/plugins/imsanity/) 7 | [![Required WP Version](https://img.shields.io/wordpress/plugin/wp-version/imsanity.svg?label=wordpress%20%3E%3D)](https://wordpress.org/plugins/imsanity/) 8 | [![Required PHP Version](https://img.shields.io/wordpress/plugin/required-php/imsanity.svg)](https://wordpress.org/plugins/imsanity/) 9 | [![GNU General Public License 3.0](https://img.shields.io/github/license/nosilver4u/imsanity.svg)](https://www.gnu.org/licenses/gpl-3.0.en.html) 10 | 11 | ## Description 12 | 13 | Automatically resize huge image uploads with Imsanity. Choose whatever size and quality you like, and let Imsanity do the rest. When a contributor uploads an image that is larger than the configured size, Imsanity will automatically scale it down to the configured size and replace the original image. 14 | 15 | Imsanity also provides a bulk-resize feature to resize previously uploaded images and free up disk space. You may resize individual images from the Media Library's List View. 16 | 17 | This plugin is ideal for blogs that do not require hi-resolution original images to be stored and/or the contributors don't want (or understand how) to scale images before uploading. 18 | 19 | You may report security issues through our Patchstack Vulnerability Disclosure Program. The Patchstack team helps validate, triage and handle any security vulnerabilities. [Report a security vulnerability.](https://patchstack.com/database/vdp/imsanity) 20 | 21 | ### Features 22 | 23 | * Automatically scales large image uploads to a more "sane" size 24 | * Bulk-resize feature to resize existing images 25 | * Selectively resize images directly in the Media Library (List View) 26 | * Allows configuration of max width/height and JPG quality 27 | * Optionally converts BMP and PNG files to JPG for more savings 28 | * Once enabled, Imsanity requires no actions on the part of the user 29 | * Uses WordPress built-in image scaling functions 30 | 31 | ### Translations 32 | 33 | Imsanity is available in several languages, each of which will be downloaded automatically when you install the plugin. To help translate it into your language, visit https://translate.wordpress.org/projects/wp-plugins/imsanity 34 | 35 | ## Installation 36 | 37 | ### Automatic Installation: 38 | 39 | 1. Go to Admin -> Plugins -> Add New and search for "imsanity" 40 | 1. Click the Install Button 41 | 1. Click 'Activate' 42 | 43 | ### Manual Installation: 44 | 45 | 1. Download imsanity.zip 46 | 1. Unzip and upload the 'imsanity' folder to your '/wp-content/plugins/' directory 47 | 1. Activate the plugin through the 'Plugins' menu in WordPress 48 | 49 | ## Frequently Asked Questions 50 | 51 | ### Will installing the Imsanity plugin alter existing images in my blog? 52 | 53 | Activating Imsanity will not alter any existing images. Imsanity resizes images as they are uploaded so it does not affect existing images unless you specifically use the "Bulk Image Resize" feature on the Imsanity settings page. The Bulk Resize feature allows you to quickly resize existing images. 54 | 55 | ### Why am I getting an error saying that my "File is not an image"? 56 | 57 | WordPress uses the GD library to handle the image manipulation. GD can be installed and configured to support various types of images. If GD is not configured to handle a particular image type then you will get this message when you try to upload it. For more info see http://php.net/manual/en/image.installation.php 58 | 59 | ### How can I tell Imsanity to ignore a certain image so I can upload it without being resized? 60 | 61 | You can re-name your file and add "-noresize" to the filename. For example if your file is named 62 | "photo.jpg" you can rename it "photo-noresize.jpg" and Imsanity will ignore it, allowing you 63 | to upload the full-sized image. 64 | 65 | If you are a developer (or have one handy), you can also use the 'imsanity_skip_image' filter to bypass resizing for any image. 66 | 67 | ### Does Imsanity compress or optimize my images? 68 | 69 | While Imsanity does compress JPG images in the process of resizing them, it uses the standard WordPress compression. Thus, the resulting images are not efficiently encoded and can be optimized further (without quality loss) by the EWWW Image Optimizer and many other image optimization plugins. 70 | 71 | ### Will Imsanity resize images from plugin X, Y, or Z? 72 | 73 | If the images can be found in the Media Library of your site, then it is likely Imsanity will resize them. Imsanity uses the wp_handle_upload hook to process new uploads and can resize any existing images in the Media Library using the Bulk Resizer. If the images are not in the Media Library, you can use the EWWW Image Optimizer to resize them. 74 | 75 | ### Why would I need this plugin? 76 | 77 | Photos taken on any modern camera and most cellphones are too large to display full-size in a browser. 78 | This wastes space on your web server, and wastes bandwidth for your visitors to view these files. 79 | 80 | Imsanity allows you to set a sanity limit so that all uploaded images will be constrained to a reasonable size which is still more than large enough for the needs of a typical website. Imsanity hooks into WordPress immediately after the image upload, but before WordPress processing occurs. So WordPress behaves exactly the same in all ways, except it will be as if the contributor had scaled their image to a reasonable size before uploading. 81 | 82 | The size limit that imsanity uses is configurable. The default value is large enough to fill the average vistor's entire screen without scaling so it is still more than large enough for typical usage. 83 | 84 | ### Why would I NOT want to use this plugin? 85 | 86 | You might not want to use Imsanity if you use WordPress as a stock art download site, to provide hi-resolution images for print or use WordPress as a hi-resolution photo storage archive. 87 | 88 | ### Doesn't WordPress already automatically scale images? 89 | 90 | When an image is uploaded WordPress keeps the original and, depending on the size of the original, will create up to 4 smaller sized copies of the file (Large, Medium-Large, Medium, Thumbnail) which are intended for embedding on your pages. Unless you have special photographic needs, the original usually sits there unused, but taking up disk quota. 91 | 92 | ### Why did you spell Insanity wrong? 93 | 94 | Imsanity is short for "Image Sanity Limit". A sanity limit is a term for limiting something down to 95 | a size or value that is reasonable. 96 | 97 | ### Where do I go for support? 98 | 99 | Questions may be posted on the support forum at https://wordpress.org/support/plugin/imsanity but if you don't get an answer, please use https://ewww.io/contact-us/. 100 | 101 | ## Credits 102 | 103 | Originally written by Jason Hinkle (RIP). Maintained and developed by [Shane Bishop](https://ewww.io) with special thanks to my [Lord and Savior](https://www.iamsecond.com/). 104 | -------------------------------------------------------------------------------- /languages/imsanity-sv_SE.po: -------------------------------------------------------------------------------- 1 | # Translation of Plugins - Imsanity - Development (trunk) in Swedish 2 | # This file is distributed under the same license as the Plugins - Imsanity - Development (trunk) package. 3 | msgid "" 4 | msgstr "" 5 | "PO-Revision-Date: 2015-09-23 14:53:56+0000\n" 6 | "MIME-Version: 1.0\n" 7 | "Content-Type: text/plain; charset=UTF-8\n" 8 | "Content-Transfer-Encoding: 8bit\n" 9 | "Plural-Forms: nplurals=2; plural=n != 1;\n" 10 | "X-Generator: GlotPress/2.3.0-alpha\n" 11 | "Language: sv_SE\n" 12 | "Project-Id-Version: Plugins - Imsanity - Development (trunk)\n" 13 | 14 | #. Author URI of the plugin/theme 15 | msgid "http://verysimple.com/" 16 | msgstr "" 17 | 18 | #. Author of the plugin/theme 19 | msgid "Jason Hinkle" 20 | msgstr "" 21 | 22 | #. Description of the plugin/theme 23 | msgid "Imsanity stops insanely huge image uploads" 24 | msgstr "" 25 | 26 | #. Plugin URI of the plugin/theme 27 | msgid "http://verysimple.com/products/imsanity/" 28 | msgstr "" 29 | 30 | #. Plugin Name of the plugin/theme 31 | msgid "Imsanity" 32 | msgstr "" 33 | 34 | #: settings.php:628 35 | msgid "Save Changes" 36 | msgstr "Spara Ändringar" 37 | 38 | #: settings.php:619 39 | msgid "Convert PNG To JPG" 40 | msgstr "" 41 | 42 | #: settings.php:611 43 | msgid "Convert BMP To JPG" 44 | msgstr "Konvertera BMP till JPG" 45 | 46 | #: settings.php:597 47 | msgid "JPG image quality" 48 | msgstr "Bildkvalitet för JPG" 49 | 50 | #: settings.php:556 51 | msgid "Imsanity settings have been configured by the server administrator. There are no site-specific settings available." 52 | msgstr "Imsanitys inställningar har konfigurerats av serveradministratören. Det finns inga webbplatsspecifika inställningar tillgängliga." 53 | 54 | #: settings.php:539 55 | msgid "Search Images..." 56 | msgstr "Sök Bilder..." 57 | 58 | #: settings.php:532 59 | msgid "" 60 | "It is HIGHLY recommended that you backup \n" 61 | "\t\tyour wp-content/uploads folder before proceeding. You will have a chance to preview and select the images to convert.\n" 62 | "\t\tIt is also recommended that you initially select only 1 or 2 images and verify that everything is ok before\n" 63 | "\t\tprocessing your entire library. You have been warned!" 64 | msgstr "" 65 | "Du rekommenderas STARKT att ta backup på \n" 66 | "\t\tdin wp-content/uploads mapp innan du fortsätter. Du kommer att få möjlighet att förhandsvisa och välja bilder att konvertera.\n" 67 | "\t\tDu rekommenderas också att först prova med 1 eller 2 bilder och kontrollera att all är ok innan\n" 68 | "\t\tdu processar hela mediabiblioteket. Du har blivit varnad!" 69 | 70 | #: settings.php:530 71 | msgid "WARNING: BULK RESIZE WILL ALTER YOUR ORIGINAL IMAGES AND CANNOT BE UNDONE!" 72 | msgstr "VARNING: BULKSKALNING KOMMER ATT ÄNDRA ORIGINALBILDERNA OCH KAN INTE ÅNGRAS!" 73 | 74 | #: settings.php:519 75 | msgid "Bulk Resize Images" 76 | msgstr "Bulkskala Bilder" 77 | 78 | #: settings.php:501 79 | msgid "Imsanity Settings" 80 | msgstr "Imsanity Inställningar" 81 | 82 | #: settings.php:484 83 | msgid "

Imsanity Version %s by %s

" 84 | msgstr "

Imsanity Version %s av %s

" 85 | 86 | #: settings.php:469 87 | msgid "" 88 | "

Imsanity automaticaly reduces the size of images that are larger than the specified maximum and replaces the original\n" 89 | "\t\twith one of a more \"sane\" size. Site contributors don\\'t need to concern themselves with manually scaling images\n" 90 | "\t\tand can upload them directly from their camera or phone.

\n" 91 | "\n" 92 | "\t\t

The resolution of modern cameras is larger than necessary for typical web display.\n" 93 | "\t\tThe average computer screen is not big enough to display a 3 megapixel camera-phone image at full resolution.\n" 94 | "\t\tWordPress does a good job of creating scaled-down copies which can be used, however the original images\n" 95 | "\t\tare permanently stored, taking up disk quota and, if used on a page, create a poor viewer experience.

\n" 96 | "\n" 97 | "\t\t

This plugin is designed for sites where high-resolution images are not necessary and/or site contributors\n" 98 | "\t\tdo not want (or understand how) to deal with scaling images. This plugin should not be used on\n" 99 | "\t\tsites for which original, high-resolution images must be stored.

\n" 100 | "\n" 101 | "\t\t

Be sure to save back-ups of your full-sized images if you wish to keep them.

" 102 | msgstr "" 103 | "

Imsanity reducerar automatiskt storleken på bilder som är större än den specificerade maxstorleken och ersätter originalet\n" 104 | "\t\tmed en version som har en mer \"sund\" storlek. Webbplatsmedarbetare behöver inte bekymra sig om att manuellt skala bilder\n" 105 | "\t\toch kan ladda upp dem direkt från sin kamera eller mobil.

\n" 106 | "\n" 107 | "\t\t

Upplösningen på moderna kameror är högre än nödvändigt för vanlig webbvisning.\n" 108 | "\t\tDen genomsnittliga datorskärmen är inte stor nog att visa en 3 megapixels bild från kamera/telefon i full upplösning.\n" 109 | "\t\tWordPress gör ett bra jobb med att skapa nedskalade kopior som kan användas, men originalbilderna\n" 110 | "\t\tlagras permanent och upptar diskutrymme och skapar en dålig visuell upplevelse för besökaren om de används på en sida.

\n" 111 | "\n" 112 | "\t\t

Detta insticksprogram är designat för webbplatser där högupplösta bilder inte är nödvändiga och/eller webbplatsmedarbetare\n" 113 | "\t\tinte vill (eller kan) skala bilder. Detta insticksprogram bör inte användas på\n" 114 | "\t\twebbplatser där högupplösta bildoriginal måste lagras.

\n" 115 | "\n" 116 | "\t\t

Se till att spara kopior av dina bildoriginal i full storlek om du vill behålla dem.

" 117 | 118 | #: settings.php:467 119 | msgid "Imsanity automatically resizes insanely huge image uploads" 120 | msgstr "Imsanity förminskar automatiskt uppladdade bilder som är galet stora" 121 | 122 | #: settings.php:286 123 | msgid "Update Settings" 124 | msgstr "Uppdatera Inställningar" 125 | 126 | #: settings.php:281 settings.php:607 127 | msgid " (WordPress default is 90)" 128 | msgstr " (Wordpress standardinställning är 90)" 129 | 130 | #: settings.php:271 131 | msgid "JPG Quality" 132 | msgstr "JPG-kvalitet" 133 | 134 | #: settings.php:263 135 | msgid "Convert PNG to JPG" 136 | msgstr "" 137 | 138 | #: settings.php:258 settings.php:266 settings.php:614 settings.php:622 139 | msgid "No" 140 | msgstr "Nej" 141 | 142 | #: settings.php:257 settings.php:265 settings.php:613 settings.php:621 143 | msgid "Yes" 144 | msgstr "Ja" 145 | 146 | #: settings.php:255 147 | msgid "Convert BMP to JPG" 148 | msgstr "Konvertera BMP till JPG" 149 | 150 | #: settings.php:247 settings.php:589 151 | msgid "Images uploaded elsewhere (Theme headers, backgrounds, logos, etc)" 152 | msgstr "Bilder uppladdade på andra ställen (Sidhuvud för teman, bakgrunder, logotyper, etc.)" 153 | 154 | #: settings.php:239 settings.php:582 155 | msgid "Images uploaded directly to the Media Library" 156 | msgstr "Bilder uppladdade direkt till Mediabiblioteket" 157 | 158 | #: settings.php:234 settings.php:242 settings.php:250 settings.php:577 159 | #: settings.php:584 settings.php:591 160 | msgid " (or enter 0 to disable)" 161 | msgstr "(eller ange 0 för att deaktivera)" 162 | 163 | #: settings.php:231 settings.php:575 164 | msgid "Images uploaded within a Page/Post" 165 | msgstr "Bilder uppladdade till en Sida/Inlägg" 166 | 167 | #: settings.php:225 168 | msgid "Use global Imsanity settings (below) for all sites" 169 | msgstr "Använd Imsanitys globala inställningar (nedan) för alla webbplatser" 170 | 171 | #: settings.php:224 172 | msgid "Allow each site to configure Imsanity settings" 173 | msgstr "Tillåt varje webbplats att konfigurera Imsanitys inställningar" 174 | 175 | #: settings.php:221 176 | msgid "Global Settings Override" 177 | msgstr "Åsidosätt Globala Inställningar" 178 | 179 | #: settings.php:207 180 | msgid "Imsanity network settings saved." 181 | msgstr "Imsanity nätverksinställningar sparades." 182 | 183 | #: settings.php:187 settings.php:200 184 | msgid "Imsanity Network Settings" 185 | msgstr "Imsanity Nätverksinställningar" 186 | 187 | #: settings.php:40 188 | msgid "Imsanity Plugin Settings" 189 | msgstr "Imsanity Programinställningar" 190 | 191 | #: libs/imagecreatefrombmp.php:129 192 | msgid "imagecreatefrombmp: %s has %d bits and this is not supported!" 193 | msgstr "imagecreatefrombmp: %s har %d bits vilket inte stöds!" 194 | 195 | #: libs/imagecreatefrombmp.php:43 196 | msgid "imagecreatefrombmp: Can not obtain filesize of %s !" 197 | msgstr "imagecreatefrombmp: Kan inte hämta filstorlek %s!" 198 | 199 | #: libs/imagecreatefrombmp.php:21 200 | msgid "imagecreatefrombmp: %s is not a bitmap!" 201 | msgstr "imagecreatefrombmp: %s är ingen bitmap!" 202 | 203 | #: libs/imagecreatefrombmp.php:14 204 | msgid "imagecreatefrombmp: Can not open %s!" 205 | msgstr "imagecreatefrombmp: Kan inte öppna %s !" 206 | 207 | #: ajax.php:185 208 | msgid "ERROR: (Attachment with ID of %s not found) " 209 | msgstr "FEL: (Bilaga med ID %s hittades ej) " 210 | 211 | #: ajax.php:179 212 | msgid "SKIPPED: %s (Resize not required)" 213 | msgstr "HOPPADE ÖVER: %s (Storleksändring behövs ej)" 214 | 215 | #: ajax.php:174 216 | msgid "ERROR: %s (%s)" 217 | msgstr "FEL: %s (%s)" 218 | 219 | #: ajax.php:170 220 | msgid "OK: %s" 221 | msgstr "OK: %s" 222 | 223 | #: ajax.php:98 224 | msgid "Missing ID Parameter" 225 | msgstr "Saknad ID-parameter" -------------------------------------------------------------------------------- /languages/imsanity-es_MX.po: -------------------------------------------------------------------------------- 1 | # Translation of Plugins - Imsanity - Development (trunk) in Spanish (Mexico) 2 | # This file is distributed under the same license as the Plugins - Imsanity - Development (trunk) package. 3 | msgid "" 4 | msgstr "" 5 | "PO-Revision-Date: 2015-12-08 16:01:42+0000\n" 6 | "MIME-Version: 1.0\n" 7 | "Content-Type: text/plain; charset=UTF-8\n" 8 | "Content-Transfer-Encoding: 8bit\n" 9 | "Plural-Forms: nplurals=2; plural=n != 1;\n" 10 | "X-Generator: GlotPress/2.3.0-alpha\n" 11 | "Language: es_MX\n" 12 | "Project-Id-Version: Plugins - Imsanity - Development (trunk)\n" 13 | 14 | #. Author URI of the plugin/theme 15 | msgid "http://verysimple.com/" 16 | msgstr "" 17 | 18 | #. Author of the plugin/theme 19 | msgid "Jason Hinkle" 20 | msgstr "" 21 | 22 | #. Description of the plugin/theme 23 | msgid "Imsanity stops insanely huge image uploads" 24 | msgstr "" 25 | 26 | #. Plugin URI of the plugin/theme 27 | msgid "http://verysimple.com/products/imsanity/" 28 | msgstr "" 29 | 30 | #. Plugin Name of the plugin/theme 31 | msgid "Imsanity" 32 | msgstr "" 33 | 34 | #: settings.php:628 35 | msgid "Save Changes" 36 | msgstr "Guardar Cambios" 37 | 38 | #: settings.php:619 39 | msgid "Convert PNG To JPG" 40 | msgstr "" 41 | 42 | #: settings.php:611 43 | msgid "Convert BMP To JPG" 44 | msgstr "Convertir BMP a JPG" 45 | 46 | #: settings.php:597 47 | msgid "JPG image quality" 48 | msgstr "Calidad de imagen JPG" 49 | 50 | #: settings.php:556 51 | msgid "Imsanity settings have been configured by the server administrator. There are no site-specific settings available." 52 | msgstr "Configuración de Imsanity se han configurado por el administrador del servidor. No se dispone de ninguna configuración específica." 53 | 54 | #: settings.php:539 55 | msgid "Search Images..." 56 | msgstr "Búsqueda de imágenes..." 57 | 58 | #: settings.php:532 59 | msgid "" 60 | "It is HIGHLY recommended that you backup \n" 61 | "\t\tyour wp-content/uploads folder before proceeding. You will have a chance to preview and select the images to convert.\n" 62 | "\t\tIt is also recommended that you initially select only 1 or 2 images and verify that everything is ok before\n" 63 | "\t\tprocessing your entire library. You have been warned!" 64 | msgstr "" 65 | "Importante! Es recomendable que realizar el backup de carpeta wp-content/uploads \\\t\\\tyour antes de proceder. Usted tendrá la oportunidad de escuchar y seleccionar las imágenes a convertir.\n" 66 | "\\\t\\\tIt también se recomienda que inicialmente seleccionar sólo 1 ó 2 imágenes y comprobar que todo está bien antes de \\\t\\\tprocessing la biblioteca entera. Estáis avisados." 67 | 68 | #: settings.php:530 69 | msgid "WARNING: BULK RESIZE WILL ALTER YOUR ORIGINAL IMAGES AND CANNOT BE UNDONE!" 70 | msgstr "ADVERTENCIA: A GRANEL RESIZE ALTERARÁ SUS IMÁGENES ORIGINALES Y NO SE PUEDE DESHACER!" 71 | 72 | #: settings.php:519 73 | msgid "Bulk Resize Images" 74 | msgstr "A granel redimensionar imágenes" 75 | 76 | #: settings.php:501 77 | msgid "Imsanity Settings" 78 | msgstr "Configuración de Imsanity" 79 | 80 | #: settings.php:484 81 | msgid "

Imsanity Version %s by %s

" 82 | msgstr "

Imsanity versión %s de %s

" 83 | 84 | #: settings.php:469 85 | msgid "" 86 | "

Imsanity automaticaly reduces the size of images that are larger than the specified maximum and replaces the original\n" 87 | "\t\twith one of a more \"sane\" size. Site contributors don\\'t need to concern themselves with manually scaling images\n" 88 | "\t\tand can upload them directly from their camera or phone.

\n" 89 | "\n" 90 | "\t\t

The resolution of modern cameras is larger than necessary for typical web display.\n" 91 | "\t\tThe average computer screen is not big enough to display a 3 megapixel camera-phone image at full resolution.\n" 92 | "\t\tWordPress does a good job of creating scaled-down copies which can be used, however the original images\n" 93 | "\t\tare permanently stored, taking up disk quota and, if used on a page, create a poor viewer experience.

\n" 94 | "\n" 95 | "\t\t

This plugin is designed for sites where high-resolution images are not necessary and/or site contributors\n" 96 | "\t\tdo not want (or understand how) to deal with scaling images. This plugin should not be used on\n" 97 | "\t\tsites for which original, high-resolution images must be stored.

\n" 98 | "\n" 99 | "\t\t

Be sure to save back-ups of your full-sized images if you wish to keep them.

" 100 | msgstr "" 101 | "

Imsanity reduce de forma automática el tamaño de las imágenes que son más grandes que el máximo especificado y sustituye al original\n" 102 | "\\\t\\\twith uno de un tamaño más\"sano\" . Colaboradores del sitio don\\'t tiene que preocuparse por la ampliación de imágenes manualmente\n" 103 | "\\\t\\\tand puede cargar directamente desde su cámara o teléfono . < / P>\n" 104 | "\n" 105 | "\\\t\\\t

La resolución de las cámaras modernas es más grande de lo necesario para la visualización web típica .\n" 106 | "\\\t\\pantalla media lLa no es lo suficientemente grande como para mostrar una imagen de la cámara - teléfono 3 megapíxeles con la máxima resolución .\n" 107 | "\\\t\\\tWordPress hace un buen trabajo de crear a escala reducida copias que se pueden utilizar , sin embargo, las imágenes originales\n" 108 | "\\\t\\\tara almacenado de forma permanente , tomando cuota de disco y , si se utiliza en una página, crear una experiencia pobre espectador. < / p>\n" 109 | "\n" 110 | "\\\t\\\t < p> Este plugin está diseñado para los sitios donde las imágenes de alta resolución no son necesarios y / o sitio contribuyentes\n" 111 | "\\\t\\\tno quieren ( o entender cómo) para hacer frente a las imágenes de escala. Este complemento no se debe utilizar en\n" 112 | "\\\t\\\tsites para que las imágenes originales de alta resolución deben ser almacenados .

\n" 113 | "\n" 114 | "\\\t\\\t

Asegúrese de guardar copias de seguridad de toda su imágenes de tamaño si lo desea para mantenerlos .

" 115 | 116 | #: settings.php:467 117 | msgid "Imsanity automatically resizes insanely huge image uploads" 118 | msgstr "Automáticamente cambia el tamaño de imagen enorme subidas" 119 | 120 | #: settings.php:286 121 | msgid "Update Settings" 122 | msgstr "Configuración de actualización" 123 | 124 | #: settings.php:281 settings.php:607 125 | msgid " (WordPress default is 90)" 126 | msgstr " (Por defecto de WordPress es 90)" 127 | 128 | #: settings.php:271 129 | msgid "JPG Quality" 130 | msgstr "Calidad JPG" 131 | 132 | #: settings.php:263 133 | msgid "Convert PNG to JPG" 134 | msgstr "" 135 | 136 | #: settings.php:258 settings.php:266 settings.php:614 settings.php:622 137 | msgid "No" 138 | msgstr "No" 139 | 140 | #: settings.php:257 settings.php:265 settings.php:613 settings.php:621 141 | msgid "Yes" 142 | msgstr "Si" 143 | 144 | #: settings.php:255 145 | msgid "Convert BMP to JPG" 146 | msgstr "Convertir BMP a JPG" 147 | 148 | #: settings.php:247 settings.php:589 149 | msgid "Images uploaded elsewhere (Theme headers, backgrounds, logos, etc)" 150 | msgstr "Imágenes subidas en otros lugares (tema cabeceras, fondos, logotipos, etc.)" 151 | 152 | #: settings.php:239 settings.php:582 153 | msgid "Images uploaded directly to the Media Library" 154 | msgstr "Imágenes subidas directamente a la biblioteca multimedia" 155 | 156 | #: settings.php:234 settings.php:242 settings.php:250 settings.php:577 157 | #: settings.php:584 settings.php:591 158 | msgid " (or enter 0 to disable)" 159 | msgstr " (o escriba 0 para desactivar)" 160 | 161 | #: settings.php:231 settings.php:575 162 | msgid "Images uploaded within a Page/Post" 163 | msgstr "Imágenes subidas dentro de un página y Post" 164 | 165 | #: settings.php:225 166 | msgid "Use global Imsanity settings (below) for all sites" 167 | msgstr "Utilice la configuración global Imsanity (abajo) para todos los sitios" 168 | 169 | #: settings.php:224 170 | msgid "Allow each site to configure Imsanity settings" 171 | msgstr "Permitir que cada sitio configurar las opciones de Imsanity" 172 | 173 | #: settings.php:221 174 | msgid "Global Settings Override" 175 | msgstr "Anulación de la configuración global" 176 | 177 | #: settings.php:207 178 | msgid "Imsanity network settings saved." 179 | msgstr "Configuración de red Imsanity guardado." 180 | 181 | #: settings.php:187 settings.php:200 182 | msgid "Imsanity Network Settings" 183 | msgstr "Configuración de red Imsanity" 184 | 185 | #: settings.php:40 186 | msgid "Imsanity Plugin Settings" 187 | msgstr "Configuración de Imsanity" 188 | 189 | #: libs/imagecreatefrombmp.php:129 190 | msgid "imagecreatefrombmp: %s has %d bits and this is not supported!" 191 | msgstr "imagecreatefrombmp: %s tiene %d bits y esto no es compatible." 192 | 193 | #: libs/imagecreatefrombmp.php:43 194 | msgid "imagecreatefrombmp: Can not obtain filesize of %s !" 195 | msgstr "imagecreatefrombmp: no puede obtener tamaño de %s!" 196 | 197 | #: libs/imagecreatefrombmp.php:21 198 | msgid "imagecreatefrombmp: %s is not a bitmap!" 199 | msgstr "imagecreatefrombmp: %s no es un mapa de bits." 200 | 201 | #: libs/imagecreatefrombmp.php:14 202 | msgid "imagecreatefrombmp: Can not open %s!" 203 | msgstr "imagecreatefrombmp: no se puede abrir %s!" 204 | 205 | #: ajax.php:185 206 | msgid "ERROR: (Attachment with ID of %s not found) " 207 | msgstr "ERROR: (Adjunto con el ID de %s no encontrado) " 208 | 209 | #: ajax.php:179 210 | msgid "SKIPPED: %s (Resize not required)" 211 | msgstr "OMITIDOS: %s (no es necesario redimensionar)" 212 | 213 | #: ajax.php:174 214 | msgid "ERROR: %s (%s)" 215 | msgstr "ERROR: %s (%s)" 216 | 217 | #: ajax.php:170 218 | msgid "OK: %s" 219 | msgstr "Bueno %s" 220 | 221 | #: ajax.php:98 222 | msgid "Missing ID Parameter" 223 | msgstr "Falta el parámetro ID" -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === Imsanity === 2 | Contributors: nosilver4u 3 | Donate link: https://ewww.io/donate/ 4 | Tags: image, scale, resize, space saver, quality 5 | Tested up to: 6.8 6 | Stable tag: 2.8.7 7 | License: GPLv3 8 | 9 | Automatically resizes huge image uploads. Are contributors uploading huge photos? Tired of manually resizing your images? Imsanity to the rescue! 10 | 11 | == Description == 12 | 13 | Automatically resize huge image uploads with Imsanity. Choose whatever size and quality you like, and let Imsanity do the rest. When a contributor uploads an image that is larger than the configured size, Imsanity will automatically scale it down to the configured size and replace the original image. 14 | 15 | Imsanity also provides a bulk-resize feature to resize previously uploaded images and free up disk space. You may resize individual images from the Media Library's List View. 16 | 17 | This plugin is ideal for blogs that do not require hi-resolution original images to be stored and/or the contributors don't want (or understand how) to scale images before uploading. 18 | 19 | You may report security issues through our Patchstack Vulnerability Disclosure Program. The Patchstack team helps validate, triage and handle any security vulnerabilities. [Report a security vulnerability.](https://patchstack.com/database/vdp/imsanity) 20 | 21 | = Features = 22 | 23 | * Automatically scales large image uploads to a more "sane" size 24 | * Bulk resize feature to resize existing images 25 | * Selectively resize images directly in the Media Library (List View) 26 | * Allows configuration of max width/height and JPG quality 27 | * Optionally converts BMP and PNG files to JPG for more savings 28 | * Once enabled, Imsanity requires no actions on the part of the user 29 | * Uses WordPress built-in image scaling functions 30 | 31 | = Translations = 32 | 33 | Imsanity is available in several languages, each of which will be downloaded automatically when you install the plugin. To help translate it into your language, visit https://translate.wordpress.org/projects/wp-plugins/imsanity 34 | 35 | = Contribute = 36 | 37 | Imsanity is developed at https://github.com/nosilver4u/imsanity (pull requests are welcome) 38 | 39 | == Installation == 40 | 41 | Automatic Installation: 42 | 43 | 1. Go to Admin -> Plugins -> Add New and search for "imsanity" 44 | 2. Click the Install Button 45 | 3. Click 'Activate' 46 | 47 | Manual Installation: 48 | 49 | 1. Download imsanity.zip 50 | 2. Unzip and upload the 'imsanity' folder to your '/wp-content/plugins/' directory 51 | 3. Activate the plugin through the 'Plugins' menu in WordPress 52 | 53 | == Screenshots == 54 | 55 | 1. Imsanity settings page to configure max height/width 56 | 2. Imsanity bulk image resize feature 57 | 58 | == Frequently Asked Questions == 59 | 60 | = Will installing the Imsanity plugin alter existing images in my blog? = 61 | 62 | Activating Imsanity will not alter any existing images. Imsanity resizes images as they are uploaded so it does not affect existing images unless you specifically use the "Bulk Image Resize" feature on the Imsanity settings page. The Bulk Resize feature allows you to quickly resize existing images. 63 | 64 | = Why am I getting an error saying that my "File is not an image" ? = 65 | 66 | WordPress uses the GD library to handle the image manipulation. GD can be installed and configured to support various types of images. If GD is not configured to handle a particular image type then you will get this message when you try to upload it. For more info see http://php.net/manual/en/image.installation.php 67 | 68 | = How can I tell Imsanity to ignore a certain image so I can upload it without being resized? = 69 | 70 | You can re-name your file and add "-noresize" to the filename. For example if your file is named "photo.jpg" you can rename it "photo-noresize.jpg" and Imsanity will ignore it, allowing you to upload the full-sized image. 71 | 72 | If you are a developer (or have one handy), you can also use the 'imsanity_skip_image' filter to bypass resizing for any image. 73 | 74 | = Does Imsanity compress or optimize my images? = 75 | 76 | While Imsanity does compress JPG images in the process of resizing them, it uses the standard WordPress compression. Thus, the resulting images are not efficiently encoded and can be optimized further (without quality loss) by the EWWW Image Optimizer and many other image optimization plugins. 77 | 78 | = Will Imsanity resize images from plugin X, Y, or Z? = 79 | 80 | If the images can be found in the Media Library of your site, then it is likely Imsanity will resize them. Imsanity uses the wp_handle_upload hook to process new uploads and can resize any existing images in the Media Library using the Bulk Resizer. If the images are not in the Media Library, you can use the EWWW Image Optimizer to resize them. 81 | 82 | = Why would I need this plugin? = 83 | 84 | Photos taken on any modern camera and most cellphones are too large to display full-size in a browser. 85 | This wastes space on your web server, and wastes bandwidth for your visitors to view these files. 86 | 87 | Imsanity allows you to set a sanity limit so that all uploaded images will be constrained to a reasonable size which is still more than large enough for the needs of a typical website. Imsanity hooks into WordPress immediately after the image upload, but before WordPress processing occurs. So WordPress behaves exactly the same in all ways, except it will be as if the contributor had scaled their image to a reasonable size before uploading. 88 | 89 | The size limit that imsanity uses is configurable. The default value is large enough to fill the average vistor's entire screen without scaling so it is still more than large enough for typical usage. 90 | 91 | = Why would I NOT want to use this plugin? = 92 | 93 | You might not want to use Imsanity if you use WordPress as a stock art download site, to provide hi-resolution images for print or use WordPress as a hi-resolution photo storage archive. 94 | 95 | = Doesn't WordPress already automatically scale images? = 96 | 97 | When an image is uploaded WordPress keeps the original and, depending on the size of the original, will create up to 4 smaller sized copies of the file (Large, Medium-Large, Medium, Thumbnail) which are intended for embedding on your pages. Unless you have special photographic needs, the original usually sits there unused, but taking up disk quota. 98 | 99 | = Why did you spell Insanity wrong? = 100 | 101 | Imsanity is short for "Image Sanity Limit". A sanity limit is a term for limiting something down to a size or value that is reasonable. 102 | 103 | = Where do I go for support? = 104 | 105 | Questions may be posted on the support forum at https://wordpress.org/support/plugin/imsanity but if you don't get an answer, please use https://ewww.io/contact-us/. 106 | 107 | == Changelog == 108 | 109 | = 2.8.7 = 110 | *Release Date = August 6, 2024* 111 | 112 | * added: change default permissions via imsanity_editor_permissions and imsanity_admin_permissions filters 113 | * changed: default permission to resize individual images changed to editor role 114 | 115 | = 2.8.6 = 116 | *Release Date - November 26, 2024* 117 | 118 | * fixed: fatal error if other plugins run big_image_size_threshold filter with too few arguments 119 | 120 | = 2.8.5 = 121 | *Release Date - November 12, 2024* 122 | 123 | * bumped WP tested version 124 | * changed: improve JSON handling/efficiency 125 | 126 | = 2.8.4 = 127 | *Release Date - April 29, 2024* 128 | 129 | * bumped WP tested version and PHP minimum 130 | 131 | = 2.8.3 = 132 | *Release Date - April 23, 2024* 133 | 134 | * changed: use updated WP coding standards 135 | * fixed: PHP 8 error trying to do math with string values 136 | 137 | = 2.8.2 = 138 | *Release Date - October 5, 2022* 139 | 140 | * fixed: mime type error when filename in attachment metadata is incorrect 141 | 142 | = 2.8.1 = 143 | *Release Date - June 16, 2022* 144 | 145 | * changed: escape and sanitize more things 146 | * changed: tighten PHPCS rules used for pre-release testing 147 | 148 | = 2.8.0 = 149 | *Release Date - May 18, 2022* 150 | 151 | * added: support for resizing WebP images via ImageMagick 152 | * changed: update attachment file size to keep WP 6.0 metadata in sync 153 | * changed: use original image for resizing if full size version was scaled by WordPress 154 | * fixed: JS scroller during bulk resize causes unexpected behavior 155 | 156 | = 2.7.2 = 157 | *Release Date - June 3, 2021* 158 | 159 | * fixed: delete originals might remove full-size version in rare cases 160 | * fixed: error thrown for image that is 1 pixel larger than max dimensions 161 | 162 | = 2.7.1 = 163 | *Release Date - November 24, 2020* 164 | 165 | * changed: clarify text for queue reset button 166 | * changed: Delete Originals function in bulk/selective resizer will clean metadata if original image is already gone 167 | 168 | = 2.7.0 = 169 | *Release Date - November 18, 2020* 170 | 171 | * changed: bulk resizer will resize all images with no limits, use list mode for selective resizing 172 | * added: see current dimensions and resize individual images in Media Library list mode 173 | * added: imsanity_disable_convert filter to bypass BMP/PNG to JPG conversion options conditionally 174 | * added: imsanity_skip_image filter to bypass resizing programmatically 175 | * added: ability to remove pre-scaled original image backup (in bulk or selectively) 176 | * changed: PNG images will not be converted if transparency is found 177 | * fixed: BMP files not converted when server uses image/x-ms-bmp as mime identifier 178 | * removed: Deep Scan option is the default behavior now, no need for configuration 179 | 180 | = Earlier versions = 181 | Please refer to the separate changelog.txt file. 182 | 183 | == Credits == 184 | 185 | Originally written by Jason Hinkle (RIP). Maintained and developed by [Shane Bishop](https://ewww.io) with special thanks to my [Lord and Savior](https://www.iamsecond.com/). 186 | -------------------------------------------------------------------------------- /imsanity.php: -------------------------------------------------------------------------------- 1 | 0 ) { 117 | imsanity_debug( 'from a post (id)' ); 118 | return IMSANITY_SOURCE_POST; 119 | } 120 | 121 | // If the referrer is the post editor, that's a good indication the image is attached to a post. 122 | if ( false !== strpos( $referer, '/post.php' ) ) { 123 | imsanity_debug( 'from a post.php' ); 124 | return IMSANITY_SOURCE_POST; 125 | } 126 | // If the referrer is the (new) post editor, that's a good indication the image is attached to a post. 127 | if ( false !== strpos( $referer, '/post-new.php' ) ) { 128 | imsanity_debug( 'from a new post' ); 129 | return IMSANITY_SOURCE_POST; 130 | } 131 | 132 | // Post_id of 0 is 3.x otherwise use the action parameter. 133 | if ( 0 === $id || 'upload-attachment' === $action ) { 134 | imsanity_debug( 'from the library' ); 135 | return IMSANITY_SOURCE_LIBRARY; 136 | } 137 | 138 | // We don't know where this one came from but $_REQUEST['_wp_http_referer'] may contain info. 139 | imsanity_debug( 'unknown source' ); 140 | return IMSANITY_SOURCE_OTHER; 141 | } 142 | 143 | /** 144 | * Given the source, returns the max width/height. 145 | * 146 | * @example: list( $w, $h ) = imsanity_get_max_width_height( IMSANITY_SOURCE_LIBRARY ); 147 | * @param int $source One of IMSANITY_SOURCE_POST | IMSANITY_SOURCE_LIBRARY | IMSANITY_SOURCE_OTHER. 148 | */ 149 | function imsanity_get_max_width_height( $source ) { 150 | $w = (int) imsanity_get_option( 'imsanity_max_width', IMSANITY_DEFAULT_MAX_WIDTH ); 151 | $h = (int) imsanity_get_option( 'imsanity_max_height', IMSANITY_DEFAULT_MAX_HEIGHT ); 152 | 153 | switch ( $source ) { 154 | case IMSANITY_SOURCE_POST: 155 | break; 156 | case IMSANITY_SOURCE_LIBRARY: 157 | $w = (int) imsanity_get_option( 'imsanity_max_width_library', $w ); 158 | $h = (int) imsanity_get_option( 'imsanity_max_height_library', $h ); 159 | break; 160 | default: 161 | $w = (int) imsanity_get_option( 'imsanity_max_width_other', $w ); 162 | $h = (int) imsanity_get_option( 'imsanity_max_height_other', $h ); 163 | break; 164 | } 165 | 166 | // NOTE: filters MUST return an array of 2 items, or the defaults will be used. 167 | return apply_filters( 'imsanity_get_max_width_height', array( $w, $h ), $source ); 168 | } 169 | 170 | /** 171 | * Handler after a file has been uploaded. If the file is an image, check the size 172 | * to see if it is too big and, if so, resize and overwrite the original. 173 | * 174 | * @param Array $params The parameters submitted with the upload. 175 | */ 176 | function imsanity_handle_upload( $params ) { 177 | 178 | // If "noresize" is included in the filename then we will bypass imsanity scaling. 179 | if ( strpos( $params['file'], 'noresize' ) !== false ) { 180 | return $params; 181 | } 182 | 183 | if ( apply_filters( 'imsanity_skip_image', false, $params['file'] ) ) { 184 | return $params; 185 | } 186 | 187 | // If preferences specify so then we can convert an original bmp or png file into jpg. 188 | if ( ( 'image/bmp' === $params['type'] || 'image/x-ms-bmp' === $params['type'] ) && imsanity_get_option( 'imsanity_bmp_to_jpg', IMSANITY_DEFAULT_BMP_TO_JPG ) ) { 189 | $params = imsanity_convert_to_jpg( 'bmp', $params ); 190 | } 191 | 192 | if ( 'image/png' === $params['type'] && imsanity_get_option( 'imsanity_png_to_jpg', IMSANITY_DEFAULT_PNG_TO_JPG ) ) { 193 | $params = imsanity_convert_to_jpg( 'png', $params ); 194 | } 195 | 196 | // Make sure this is a type of image that we want to convert and that it exists. 197 | $oldpath = $params['file']; 198 | 199 | // Let folks filter the allowed mime-types for resizing. 200 | $allowed_types = apply_filters( 'imsanity_allowed_mimes', array( 'image/png', 'image/gif', 'image/jpeg' ), $oldpath ); 201 | if ( is_string( $allowed_types ) ) { 202 | $allowed_types = array( $allowed_types ); 203 | } elseif ( ! is_array( $allowed_types ) ) { 204 | $allowed_types = array(); 205 | } 206 | 207 | if ( 208 | ( ! is_wp_error( $params ) ) && 209 | is_file( $oldpath ) && 210 | is_readable( $oldpath ) && 211 | is_writable( $oldpath ) && 212 | filesize( $oldpath ) > 0 && 213 | in_array( $params['type'], $allowed_types, true ) 214 | ) { 215 | 216 | // figure out where the upload is coming from. 217 | $source = imsanity_get_source(); 218 | 219 | $maxw = IMSANITY_DEFAULT_MAX_WIDTH; 220 | $maxh = IMSANITY_DEFAULT_MAX_HEIGHT; 221 | $max_width_height = imsanity_get_max_width_height( $source ); 222 | if ( is_array( $max_width_height ) && 2 === count( $max_width_height ) ) { 223 | list( $maxw, $maxh ) = $max_width_height; 224 | } 225 | $maxw = (int) $maxw; 226 | $maxh = (int) $maxh; 227 | 228 | list( $oldw, $oldh ) = getimagesize( $oldpath ); 229 | 230 | if ( ( $oldw > $maxw + 1 && $maxw > 0 ) || ( $oldh > $maxh + 1 && $maxh > 0 ) ) { 231 | $quality = imsanity_get_option( 'imsanity_quality', IMSANITY_DEFAULT_QUALITY ); 232 | 233 | $ftype = imsanity_quick_mimetype( $oldpath ); 234 | $orientation = imsanity_get_orientation( $oldpath, $ftype ); 235 | // If we are going to rotate the image 90 degrees during the resize, swap the existing image dimensions. 236 | if ( 6 === (int) $orientation || 8 === (int) $orientation ) { 237 | $old_oldw = $oldw; 238 | $oldw = $oldh; 239 | $oldh = $old_oldw; 240 | } 241 | 242 | if ( $maxw > 0 && $maxh > 0 && $oldw >= $maxw && $oldh >= $maxh && ( $oldh > $maxh || $oldw > $maxw ) && apply_filters( 'imsanity_crop_image', false ) ) { 243 | $neww = $maxw; 244 | $newh = $maxh; 245 | } else { 246 | list( $neww, $newh ) = wp_constrain_dimensions( $oldw, $oldh, $maxw, $maxh ); 247 | } 248 | 249 | global $ewww_preempt_editor; 250 | if ( ! isset( $ewww_preempt_editor ) ) { 251 | $ewww_preempt_editor = false; 252 | } 253 | $original_preempt = $ewww_preempt_editor; 254 | $ewww_preempt_editor = true; 255 | $resizeresult = imsanity_image_resize( $oldpath, $neww, $newh, apply_filters( 'imsanity_crop_image', false ), null, null, $quality ); 256 | $ewww_preempt_editor = $original_preempt; 257 | 258 | if ( $resizeresult && ! is_wp_error( $resizeresult ) ) { 259 | $newpath = $resizeresult; 260 | 261 | if ( is_file( $newpath ) && filesize( $newpath ) < filesize( $oldpath ) ) { 262 | // We saved some file space. remove original and replace with resized image. 263 | unlink( $oldpath ); 264 | rename( $newpath, $oldpath ); 265 | } elseif ( is_file( $newpath ) ) { 266 | // The resized image is actually bigger in filesize (most likely due to jpg quality). 267 | // Keep the old one and just get rid of the resized image. 268 | unlink( $newpath ); 269 | } 270 | } elseif ( false === $resizeresult ) { 271 | return $params; 272 | } elseif ( is_wp_error( $resizeresult ) ) { 273 | // resize didn't work, likely because the image processing libraries are missing. 274 | // remove the old image so we don't leave orphan files hanging around. 275 | unlink( $oldpath ); 276 | 277 | $params = wp_handle_upload_error( 278 | $oldpath, 279 | sprintf( 280 | /* translators: 1: error message 2: link to support forums */ 281 | esc_html__( 'Imsanity was unable to resize this image for the following reason: %1$s. If you continue to see this error message, you may need to install missing server components. If you think you have discovered a bug, please report it on the Imsanity support forum: %2$s', 'imsanity' ), 282 | $resizeresult->get_error_message(), 283 | 'https://wordpress.org/support/plugin/imsanity' 284 | ) 285 | ); 286 | } else { 287 | return $params; 288 | } 289 | } 290 | } 291 | clearstatcache(); 292 | return $params; 293 | } 294 | 295 | 296 | /** 297 | * Read in the image file from the params and then save as a new jpg file. 298 | * if successful, remove the original image and alter the return 299 | * parameters to return the new jpg instead of the original 300 | * 301 | * @param string $type Type of the image to be converted: 'bmp' or 'png'. 302 | * @param array $params The upload parameters. 303 | * @return array altered params 304 | */ 305 | function imsanity_convert_to_jpg( $type, $params ) { 306 | 307 | if ( apply_filters( 'imsanity_disable_convert', false, $type, $params ) ) { 308 | return $params; 309 | } 310 | 311 | $img = null; 312 | 313 | if ( 'bmp' === $type ) { 314 | if ( ! function_exists( 'imagecreatefrombmp' ) ) { 315 | return $params; 316 | } 317 | $img = imagecreatefrombmp( $params['file'] ); 318 | } elseif ( 'png' === $type ) { 319 | // Prevent converting PNG images with alpha/transparency, unless overridden by the user. 320 | if ( apply_filters( 'imsanity_skip_alpha', imsanity_has_alpha( $params['file'] ), $params['file'] ) ) { 321 | return $params; 322 | } 323 | if ( ! function_exists( 'imagecreatefrompng' ) ) { 324 | return wp_handle_upload_error( $params['file'], esc_html__( 'Imsanity requires the GD library to convert PNG images to JPG', 'imsanity' ) ); 325 | } 326 | 327 | $input = imagecreatefrompng( $params['file'] ); 328 | // convert png transparency to white. 329 | $img = imagecreatetruecolor( imagesx( $input ), imagesy( $input ) ); 330 | imagefill( $img, 0, 0, imagecolorallocate( $img, 255, 255, 255 ) ); 331 | imagealphablending( $img, true ); 332 | imagecopy( $img, $input, 0, 0, 0, 0, imagesx( $input ), imagesy( $input ) ); 333 | } else { 334 | return wp_handle_upload_error( $params['file'], esc_html__( 'Unknown image type specified in imsanity_convert_to_jpg', 'imsanity' ) ); 335 | } 336 | 337 | // We need to change the extension from the original to .jpg so we have to ensure it will be a unique filename. 338 | $uploads = wp_upload_dir(); 339 | $oldfilename = wp_basename( $params['file'] ); 340 | $newfilename = wp_basename( str_ireplace( '.' . $type, '.jpg', $oldfilename ) ); 341 | $newfilename = wp_unique_filename( $uploads['path'], $newfilename ); 342 | 343 | $quality = imsanity_get_option( 'imsanity_quality', IMSANITY_DEFAULT_QUALITY ); 344 | 345 | if ( imagejpeg( $img, $uploads['path'] . '/' . $newfilename, $quality ) ) { 346 | // Conversion succeeded: remove the original bmp & remap the params. 347 | unlink( $params['file'] ); 348 | 349 | $params['file'] = $uploads['path'] . '/' . $newfilename; 350 | $params['url'] = $uploads['url'] . '/' . $newfilename; 351 | $params['type'] = 'image/jpeg'; 352 | } else { 353 | unlink( $params['file'] ); 354 | 355 | return wp_handle_upload_error( 356 | $oldfilename, 357 | /* translators: %s: the image mime type */ 358 | sprintf( esc_html__( 'Imsanity was unable to process the %s file. If you continue to see this error you may need to disable the conversion option in the Imsanity settings.', 'imsanity' ), $type ) 359 | ); 360 | } 361 | 362 | return $params; 363 | } 364 | 365 | // Add filter to hook into uploads. 366 | add_filter( 'wp_handle_upload', 'imsanity_handle_upload' ); 367 | // Run necessary actions on init (loading translations mostly). 368 | add_action( 'plugins_loaded', 'imsanity_init' ); 369 | 370 | // Adds a column to the media library list view to display optimization results. 371 | add_filter( 'manage_media_columns', 'imsanity_media_columns' ); 372 | // Outputs the actual column information for each attachment. 373 | add_action( 'manage_media_custom_column', 'imsanity_custom_column', 10, 2 ); 374 | // Checks for WebP support and adds it to the allowed mime types. 375 | add_filter( 'imsanity_allowed_mimes', 'imsanity_add_webp_support' ); 376 | -------------------------------------------------------------------------------- /libs/utils.php: -------------------------------------------------------------------------------- 1 | queryFormats(); 90 | if ( in_array( 'WEBP', $formats, true ) ) { 91 | $mimes[] = 'image/webp'; 92 | } 93 | } 94 | } 95 | return $mimes; 96 | } 97 | 98 | /** 99 | * Gets the orientation/rotation of a JPG image using the EXIF data. 100 | * 101 | * @param string $file Name of the file. 102 | * @param string $type Mime type of the file. 103 | * @return int|bool The orientation value or false. 104 | */ 105 | function imsanity_get_orientation( $file, $type ) { 106 | if ( function_exists( 'exif_read_data' ) && 'image/jpeg' === $type ) { 107 | $exif = @exif_read_data( $file ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged 108 | if ( is_array( $exif ) && array_key_exists( 'Orientation', $exif ) ) { 109 | return (int) $exif['Orientation']; 110 | } 111 | } 112 | return false; 113 | } 114 | 115 | /** 116 | * Check an image to see if it has transparency. 117 | * 118 | * @param string $filename The name of the image file. 119 | * @return bool True if transparency is found. 120 | */ 121 | function imsanity_has_alpha( $filename ) { 122 | if ( ! is_file( $filename ) ) { 123 | return false; 124 | } 125 | if ( false !== strpos( $filename, '../' ) ) { 126 | return false; 127 | } 128 | $file_contents = file_get_contents( $filename ); 129 | // Determine what color type is stored in the file. 130 | $color_type = ord( substr( $file_contents, 25, 1 ) ); 131 | // If we do not have GD and the PNG color type is RGB alpha or Grayscale alpha. 132 | if ( ! imsanity_gd_support() && ( 4 === $color_type || 6 === $color_type ) ) { 133 | return true; 134 | } elseif ( imsanity_gd_support() ) { 135 | $image = imagecreatefrompng( $filename ); 136 | if ( imagecolortransparent( $image ) >= 0 ) { 137 | return true; 138 | } 139 | list( $width, $height ) = getimagesize( $filename ); 140 | for ( $y = 0; $y < $height; $y++ ) { 141 | for ( $x = 0; $x < $width; $x++ ) { 142 | $color = imagecolorat( $image, $x, $y ); 143 | $rgb = imagecolorsforindex( $image, $color ); 144 | if ( $rgb['alpha'] > 0 ) { 145 | return true; 146 | } 147 | } 148 | } 149 | } 150 | return false; 151 | } 152 | 153 | /** 154 | * Check for GD support of both PNG and JPG. 155 | * 156 | * @return bool True if full GD support is detected. 157 | */ 158 | function imsanity_gd_support() { 159 | if ( function_exists( 'gd_info' ) ) { 160 | $gd_support = gd_info(); 161 | if ( is_iterable( $gd_support ) ) { 162 | if ( ( ! empty( $gd_support['JPEG Support'] ) || ! empty( $gd_support['JPG Support'] ) ) && ! empty( $gd_support['PNG Support'] ) ) { 163 | return true; 164 | } 165 | } 166 | } 167 | return false; 168 | } 169 | 170 | /** 171 | * Resizes the image with the given id according to the configured max width and height settings. 172 | * 173 | * @param int $id The attachment ID of the image to process. 174 | * @return array The success status (bool) and a message to display. 175 | */ 176 | function imsanity_resize_from_id( $id = 0 ) { 177 | 178 | $id = (int) $id; 179 | 180 | if ( ! $id ) { 181 | return; 182 | } 183 | 184 | $meta = wp_get_attachment_metadata( $id ); 185 | 186 | if ( $meta && is_array( $meta ) ) { 187 | $update_meta = false; 188 | // If "noresize" is included in the filename then we will bypass imsanity scaling. 189 | if ( ! empty( $meta['file'] ) && false !== strpos( $meta['file'], 'noresize' ) ) { 190 | /* translators: %s: File-name of the image */ 191 | $msg = sprintf( esc_html__( 'SKIPPED: %s (noresize)', 'imsanity' ), $meta['file'] ); 192 | return array( 193 | 'success' => false, 194 | 'message' => $msg, 195 | ); 196 | } 197 | 198 | // $uploads = wp_upload_dir(); 199 | $oldpath = imsanity_attachment_path( $meta, $id, '', false ); 200 | 201 | if ( empty( $oldpath ) ) { 202 | /* translators: %s: File-name of the image */ 203 | $msg = sprintf( esc_html__( 'Could not retrieve location of %s', 'imsanity' ), $meta['file'] ); 204 | return array( 205 | 'success' => false, 206 | 'message' => $msg, 207 | ); 208 | } 209 | 210 | // Let folks filter the allowed mime-types for resizing. 211 | $allowed_types = apply_filters( 'imsanity_allowed_mimes', array( 'image/png', 'image/gif', 'image/jpeg' ), $oldpath ); 212 | if ( is_string( $allowed_types ) ) { 213 | $allowed_types = array( $allowed_types ); 214 | } elseif ( ! is_array( $allowed_types ) ) { 215 | $allowed_types = array(); 216 | } 217 | $ftype = imsanity_quick_mimetype( $oldpath ); 218 | if ( ! in_array( $ftype, $allowed_types, true ) ) { 219 | /* translators: %s: File type of the image */ 220 | $msg = sprintf( esc_html__( '%1$s does not have an allowed file type (%2$s)', 'imsanity' ), wp_basename( $oldpath ), $ftype ); 221 | return array( 222 | 'success' => false, 223 | 'message' => $msg, 224 | ); 225 | } 226 | 227 | if ( ! is_writable( $oldpath ) ) { 228 | /* translators: %s: File-name of the image */ 229 | $msg = sprintf( esc_html__( '%s is not writable', 'imsanity' ), $meta['file'] ); 230 | return array( 231 | 'success' => false, 232 | 'message' => $msg, 233 | ); 234 | } 235 | 236 | if ( apply_filters( 'imsanity_skip_image', false, $oldpath ) ) { 237 | /* translators: %s: File-name of the image */ 238 | $msg = sprintf( esc_html__( 'SKIPPED: %s (by user exclusion)', 'imsanity' ), $meta['file'] ); 239 | return array( 240 | 'success' => false, 241 | 'message' => $msg, 242 | ); 243 | } 244 | 245 | $maxw = imsanity_get_option( 'imsanity_max_width', IMSANITY_DEFAULT_MAX_WIDTH ); 246 | $maxh = imsanity_get_option( 'imsanity_max_height', IMSANITY_DEFAULT_MAX_HEIGHT ); 247 | 248 | // method one - slow but accurate, get file size from file itself. 249 | list( $oldw, $oldh ) = getimagesize( $oldpath ); 250 | // method two - get file size from meta, fast but resize will fail if meta is out of sync. 251 | if ( ! $oldw || ! $oldh ) { 252 | $oldw = $meta['width']; 253 | $oldh = $meta['height']; 254 | } 255 | 256 | if ( ( $oldw > $maxw && $maxw > 0 ) || ( $oldh > $maxh && $maxh > 0 ) ) { 257 | $quality = imsanity_get_option( 'imsanity_quality', IMSANITY_DEFAULT_QUALITY ); 258 | 259 | if ( $maxw > 0 && $maxh > 0 && $oldw >= $maxw && $oldh >= $maxh && ( $oldh > $maxh || $oldw > $maxw ) && apply_filters( 'imsanity_crop_image', false ) ) { 260 | $neww = $maxw; 261 | $newh = $maxh; 262 | } else { 263 | list( $neww, $newh ) = wp_constrain_dimensions( $oldw, $oldh, $maxw, $maxh ); 264 | } 265 | 266 | $source_image = $oldpath; 267 | if ( ! empty( $meta['original_image'] ) ) { 268 | $source_image = path_join( dirname( $oldpath ), $meta['original_image'] ); 269 | imsanity_debug( "subbing in $source_image for resizing" ); 270 | } 271 | $resizeresult = imsanity_image_resize( $source_image, $neww, $newh, apply_filters( 'imsanity_crop_image', false ), null, null, $quality ); 272 | 273 | if ( $resizeresult && ! is_wp_error( $resizeresult ) ) { 274 | $newpath = $resizeresult; 275 | 276 | if ( $newpath !== $oldpath && is_file( $newpath ) && filesize( $newpath ) < filesize( $oldpath ) ) { 277 | // we saved some file space. remove original and replace with resized image. 278 | unlink( $oldpath ); 279 | rename( $newpath, $oldpath ); 280 | $meta['width'] = $neww; 281 | $meta['height'] = $newh; 282 | 283 | $update_meta = true; 284 | 285 | $results = array( 286 | 'success' => true, 287 | 'id' => $id, 288 | /* translators: 1: File-name of the image */ 289 | 'message' => sprintf( esc_html__( 'OK: %1$s resized to %2$s x %3$s', 'imsanity' ), $meta['file'], $neww . 'w', $newh . 'h' ), 290 | ); 291 | } elseif ( $newpath !== $oldpath ) { 292 | // the resized image is actually bigger in filesize (most likely due to jpg quality). 293 | // keep the old one and just get rid of the resized image. 294 | if ( is_file( $newpath ) ) { 295 | unlink( $newpath ); 296 | } 297 | $results = array( 298 | 'success' => false, 299 | 'id' => $id, 300 | /* translators: 1: File-name of the image 2: the error message, translated elsewhere */ 301 | 'message' => sprintf( esc_html__( 'ERROR: %1$s (%2$s)', 'imsanity' ), $meta['file'], esc_html__( 'File size of resized image was larger than the original', 'imsanity' ) ), 302 | ); 303 | } else { 304 | $results = array( 305 | 'success' => false, 306 | 'id' => $id, 307 | /* translators: 1: File-name of the image 2: the error message, translated elsewhere */ 308 | 'message' => sprintf( esc_html__( 'ERROR: %1$s (%2$s)', 'imsanity' ), $meta['file'], esc_html__( 'Unknown error, resizing function returned the same filename', 'imsanity' ) ), 309 | ); 310 | } 311 | } elseif ( false === $resizeresult ) { 312 | $results = array( 313 | 'success' => false, 314 | 'id' => $id, 315 | /* translators: 1: File-name of the image 2: the error message, translated elsewhere */ 316 | 'message' => sprintf( esc_html__( 'ERROR: %1$s (%2$s)', 'imsanity' ), $meta['file'], esc_html__( 'wp_get_image_editor missing', 'imsanity' ) ), 317 | ); 318 | } else { 319 | $results = array( 320 | 'success' => false, 321 | 'id' => $id, 322 | /* translators: 1: File-name of the image 2: the error message, translated elsewhere */ 323 | 'message' => sprintf( esc_html__( 'ERROR: %1$s (%2$s)', 'imsanity' ), $meta['file'], htmlentities( $resizeresult->get_error_message() ) ), 324 | ); 325 | } 326 | } else { 327 | $results = array( 328 | 'success' => true, 329 | 'id' => $id, 330 | /* translators: %s: File-name of the image */ 331 | 'message' => sprintf( esc_html__( 'SKIPPED: %s (Resize not required)', 'imsanity' ), $meta['file'] ) . " -- $oldw x $oldh", 332 | ); 333 | if ( empty( $meta['width'] ) || empty( $meta['height'] ) ) { 334 | if ( empty( $meta['width'] ) || $meta['width'] > $oldw ) { 335 | $meta['width'] = $oldw; 336 | } 337 | if ( empty( $meta['height'] ) || $meta['height'] > $oldh ) { 338 | $meta['height'] = $oldh; 339 | } 340 | $update_meta = true; 341 | } 342 | } 343 | $remove_original = imsanity_remove_original_image( $id, $meta ); 344 | if ( $remove_original && is_array( $remove_original ) ) { 345 | $meta = $remove_original; 346 | $update_meta = true; 347 | } 348 | if ( ! empty( $update_meta ) ) { 349 | clearstatcache(); 350 | if ( ! empty( $oldpath ) && is_file( $oldpath ) ) { 351 | $meta['filesize'] = filesize( $oldpath ); 352 | } 353 | wp_update_attachment_metadata( $id, $meta ); 354 | do_action( 'imsanity_post_process_attachment', $id, $meta ); 355 | } 356 | } else { 357 | $results = array( 358 | 'success' => false, 359 | 'id' => $id, 360 | /* translators: %s: ID number of the image */ 361 | 'message' => sprintf( esc_html__( 'ERROR: Attachment with ID of %d not found', 'imsanity' ), intval( $id ) ), 362 | ); 363 | } 364 | 365 | // If there is a quota we need to reset the directory size cache so it will re-calculate. 366 | delete_transient( 'dirsize_cache' ); 367 | 368 | return $results; 369 | } 370 | 371 | /** 372 | * Find the path to a backed-up original (not the full-size version like the core WP function). 373 | * 374 | * @param int $id The attachment ID number. 375 | * @param string $image_file The path to a scaled image file. 376 | * @param array $meta The attachment metadata. Optional, default to null. 377 | * @return bool True on success, false on failure. 378 | */ 379 | function imsanity_get_original_image_path( $id, $image_file = '', $meta = null ) { 380 | $id = (int) $id; 381 | if ( empty( $id ) ) { 382 | return false; 383 | } 384 | if ( ! wp_attachment_is_image( $id ) ) { 385 | return false; 386 | } 387 | if ( is_null( $meta ) ) { 388 | $meta = wp_get_attachment_metadata( $id ); 389 | } 390 | if ( empty( $image_file ) ) { 391 | $image_file = get_attached_file( $id, true ); 392 | } 393 | if ( empty( $image_file ) || ! is_iterable( $meta ) || empty( $meta['original_image'] ) ) { 394 | return false; 395 | } 396 | 397 | return trailingslashit( dirname( $image_file ) ) . wp_basename( $meta['original_image'] ); 398 | } 399 | 400 | /** 401 | * Remove the backed-up original_image stored by WP 5.3+. 402 | * 403 | * @param int $id The attachment ID number. 404 | * @param array $meta The attachment metadata. Optional, default to null. 405 | * @return bool|array Returns meta if modified, false otherwise (even if an "unlinked" original is removed). 406 | */ 407 | function imsanity_remove_original_image( $id, $meta = null ) { 408 | $id = (int) $id; 409 | if ( empty( $id ) ) { 410 | return false; 411 | } 412 | if ( is_null( $meta ) ) { 413 | $meta = wp_get_attachment_metadata( $id ); 414 | } 415 | 416 | if ( 417 | $meta && is_array( $meta ) && 418 | imsanity_get_option( 'imsanity_delete_originals', false ) && 419 | ! empty( $meta['original_image'] ) && function_exists( 'wp_get_original_image_path' ) 420 | ) { 421 | $original_image = imsanity_get_original_image_path( $id, '', $meta ); 422 | if ( $original_image && is_file( $original_image ) && is_writable( $original_image ) ) { 423 | unlink( $original_image ); 424 | } 425 | clearstatcache(); 426 | if ( empty( $original_image ) || ! is_file( $original_image ) ) { 427 | unset( $meta['original_image'] ); 428 | return $meta; 429 | } 430 | } 431 | return false; 432 | } 433 | 434 | /** 435 | * Resize an image using the WP_Image_Editor. 436 | * 437 | * @param string $file Image file path. 438 | * @param int $max_w Maximum width to resize to. 439 | * @param int $max_h Maximum height to resize to. 440 | * @param bool $crop Optional. Whether to crop image or resize. 441 | * @param string $suffix Optional. File suffix. 442 | * @param string $dest_path Optional. New image file path. 443 | * @param int $jpeg_quality Optional, default is 82. Image quality level (1-100). 444 | * @return mixed WP_Error on failure. String with new destination path. 445 | */ 446 | function imsanity_image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 82 ) { 447 | if ( function_exists( 'wp_get_image_editor' ) ) { 448 | imsanity_debug( "resizing $file" ); 449 | $editor = wp_get_image_editor( $file ); 450 | if ( is_wp_error( $editor ) ) { 451 | return $editor; 452 | } 453 | 454 | $ftype = imsanity_quick_mimetype( $file ); 455 | if ( 'image/webp' === $ftype ) { 456 | $jpeg_quality = (int) round( $jpeg_quality * .91 ); 457 | } 458 | 459 | $editor->set_quality( min( 92, $jpeg_quality ) ); 460 | 461 | // Return 1 to override auto-rotate. 462 | $orientation = (int) apply_filters( 'imsanity_orientation', imsanity_get_orientation( $file, $ftype ) ); 463 | // Try to correct for auto-rotation if the info is available. 464 | switch ( $orientation ) { 465 | case 3: 466 | $editor->rotate( 180 ); 467 | break; 468 | case 6: 469 | $editor->rotate( -90 ); 470 | break; 471 | case 8: 472 | $editor->rotate( 90 ); 473 | break; 474 | } 475 | 476 | $resized = $editor->resize( $max_w, $max_h, $crop ); 477 | if ( is_wp_error( $resized ) ) { 478 | return $resized; 479 | } 480 | 481 | $dest_file = $editor->generate_filename( $suffix, $dest_path ); 482 | 483 | // Make sure that the destination file does not exist. 484 | if ( file_exists( $dest_file ) ) { 485 | $dest_file = $editor->generate_filename( 'TMP', $dest_path ); 486 | } 487 | 488 | $saved = $editor->save( $dest_file ); 489 | 490 | if ( is_wp_error( $saved ) ) { 491 | return $saved; 492 | } 493 | 494 | return $dest_file; 495 | } 496 | return false; 497 | } 498 | -------------------------------------------------------------------------------- /settings.php: -------------------------------------------------------------------------------- 1 | imsanity_ms ) ) { 11 | $wpdb->imsanity_ms = $wpdb->get_blog_prefix( 0 ) . 'imsanity'; 12 | } 13 | 14 | // Register the plugin settings menu. 15 | add_action( 'admin_menu', 'imsanity_create_menu' ); 16 | add_action( 'network_admin_menu', 'imsanity_register_network' ); 17 | add_filter( 'plugin_action_links_' . IMSANITY_PLUGIN_FILE_REL, 'imsanity_settings_link' ); 18 | add_filter( 'network_admin_plugin_action_links_' . IMSANITY_PLUGIN_FILE_REL, 'imsanity_settings_link' ); 19 | add_action( 'admin_enqueue_scripts', 'imsanity_queue_script' ); 20 | add_action( 'admin_init', 'imsanity_register_settings' ); 21 | add_filter( 'big_image_size_threshold', 'imsanity_adjust_default_threshold', 10, 3 ); 22 | 23 | register_activation_hook( IMSANITY_PLUGIN_FILE_REL, 'imsanity_maybe_created_custom_table' ); 24 | 25 | // settings cache. 26 | $_imsanity_multisite_settings = null; 27 | 28 | /** 29 | * Create the settings menu item in the WordPress admin navigation and 30 | * link it to the plugin settings page 31 | */ 32 | function imsanity_create_menu() { 33 | $permissions = apply_filters( 'imsanity_admin_permissions', 'manage_options' ); 34 | // Create new menu for site configuration. 35 | add_options_page( 36 | esc_html__( 'Imsanity Plugin Settings', 'imsanity' ), // Page Title. 37 | esc_html__( 'Imsanity', 'imsanity' ), // Menu Title. 38 | $permissions, // Required permissions. 39 | IMSANITY_PLUGIN_FILE_REL, // Slug. 40 | 'imsanity_settings_page' // Function to call. 41 | ); 42 | } 43 | 44 | /** 45 | * Register the network settings page 46 | */ 47 | function imsanity_register_network() { 48 | if ( ! function_exists( 'is_plugin_active_for_network' ) && is_multisite() ) { 49 | // Need to include the plugin library for the is_plugin_active function. 50 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; 51 | } 52 | if ( is_multisite() ) { 53 | $permissions = apply_filters( 'imsanity_superadmin_permissions', 'manage_network_options' ); 54 | add_submenu_page( 55 | 'settings.php', 56 | esc_html__( 'Imsanity Network Settings', 'imsanity' ), 57 | esc_html__( 'Imsanity', 'imsanity' ), 58 | $permissions, 59 | IMSANITY_PLUGIN_FILE_REL, 60 | 'imsanity_network_settings' 61 | ); 62 | } 63 | } 64 | 65 | /** 66 | * Settings link that appears on the plugins overview page 67 | * 68 | * @param array $links The plugin action links. 69 | * @return array The action links, with a settings link pre-pended. 70 | */ 71 | function imsanity_settings_link( $links ) { 72 | if ( ! is_array( $links ) ) { 73 | $links = array(); 74 | } 75 | if ( is_multisite() && is_network_admin() ) { 76 | $settings_link = '' . esc_html__( 'Settings', 'imsanity' ) . ''; 77 | } else { 78 | $settings_link = '' . esc_html__( 'Settings', 'imsanity' ) . ''; 79 | } 80 | array_unshift( $links, $settings_link ); 81 | return $links; 82 | } 83 | 84 | /** 85 | * Queues up the AJAX script and any localized JS vars we need. 86 | * 87 | * @param string $hook The hook name for the current page. 88 | */ 89 | function imsanity_queue_script( $hook ) { 90 | // Make sure we are being called from the settings page. 91 | if ( strpos( $hook, 'settings_page_imsanity' ) !== 0 && 'upload.php' !== $hook ) { 92 | return; 93 | } 94 | if ( ! empty( $_REQUEST['imsanity_reset'] ) && ! empty( $_REQUEST['imsanity_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_REQUEST['imsanity_wpnonce'] ), 'imsanity-bulk-reset' ) ) { 95 | update_option( 'imsanity_resume_id', 0, false ); 96 | } 97 | $resume_id = (int) get_option( 'imsanity_resume_id' ); 98 | $loading_image = plugins_url( '/images/ajax-loader.gif', __FILE__ ); 99 | // Register the scripts that are used by the bulk resizer. 100 | wp_enqueue_script( 'imsanity_script', plugins_url( '/scripts/imsanity.js', __FILE__ ), array( 'jquery' ), IMSANITY_VERSION ); 101 | wp_localize_script( 102 | 'imsanity_script', 103 | 'imsanity_vars', 104 | array( 105 | '_wpnonce' => wp_create_nonce( 'imsanity-bulk' ), 106 | 'resize_all_prompt' => esc_html__( 'You are about to resize all your existing images. Please be sure your site is backed up before proceeding. Do you wish to continue?', 'imsanity' ), 107 | 'resizing_complete' => esc_html__( 'Resizing Complete', 'imsanity' ) . ' - ' . esc_html__( 'Leave a Review', 'imsanity' ) . '', 108 | 'resize_selected' => esc_html__( 'Resize Selected Images', 'imsanity' ), 109 | 'resizing' => '

' . esc_html__( 'Please wait...', 'imsanity' ) . " 

", 110 | 'removal_failed' => esc_html__( 'Removal Failed', 'imsanity' ), 111 | 'removal_succeeded' => esc_html__( 'Removal Complete', 'imsanity' ), 112 | 'operation_stopped' => esc_html__( 'Resizing stopped, reload page to resume.', 'imsanity' ), 113 | 'image' => esc_html__( 'Image', 'imsanity' ), 114 | 'invalid_response' => esc_html__( 'Received an invalid response, please check for errors in the Developer Tools console of your browser.', 'imsanity' ), 115 | 'none_found' => esc_html__( 'There are no images that need to be resized.', 'imsanity' ), 116 | 'resume_id' => $resume_id, 117 | ) 118 | ); 119 | add_action( 'admin_notices', 'imsanity_missing_gd_admin_notice' ); 120 | add_action( 'network_admin_notices', 'imsanity_missing_gd_admin_notice' ); 121 | add_action( 'admin_print_scripts', 'imsanity_settings_css' ); 122 | } 123 | 124 | /** 125 | * Return true if the multi-site settings table exists 126 | * 127 | * @return bool True if the Imsanity table exists. 128 | */ 129 | function imsanity_multisite_table_exists() { 130 | global $wpdb; 131 | return $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->imsanity_ms'" ) === $wpdb->imsanity_ms; 132 | } 133 | 134 | /** 135 | * Checks the schema version for the Imsanity table. 136 | * 137 | * @return string The version identifier for the schema. 138 | */ 139 | function imsanity_multisite_table_schema_version() { 140 | // If the table doesn't exist then there is no schema to report. 141 | if ( ! imsanity_multisite_table_exists() ) { 142 | return '0'; 143 | } 144 | 145 | global $wpdb; 146 | $version = $wpdb->get_var( "SELECT data FROM $wpdb->imsanity_ms WHERE setting = 'schema'" ); 147 | 148 | if ( ! $version ) { 149 | $version = '1.0'; // This is a legacy version 1.0 installation. 150 | } 151 | 152 | return $version; 153 | } 154 | 155 | /** 156 | * Returns the default network settings in the case where they are not 157 | * defined in the database, or multi-site is not enabled. 158 | * 159 | * @return stdClass 160 | */ 161 | function imsanity_get_default_multisite_settings() { 162 | $data = new stdClass(); 163 | 164 | $data->imsanity_override_site = false; 165 | $data->imsanity_max_height = IMSANITY_DEFAULT_MAX_HEIGHT; 166 | $data->imsanity_max_width = IMSANITY_DEFAULT_MAX_WIDTH; 167 | $data->imsanity_max_height_library = IMSANITY_DEFAULT_MAX_HEIGHT; 168 | $data->imsanity_max_width_library = IMSANITY_DEFAULT_MAX_WIDTH; 169 | $data->imsanity_max_height_other = IMSANITY_DEFAULT_MAX_HEIGHT; 170 | $data->imsanity_max_width_other = IMSANITY_DEFAULT_MAX_WIDTH; 171 | $data->imsanity_bmp_to_jpg = IMSANITY_DEFAULT_BMP_TO_JPG; 172 | $data->imsanity_png_to_jpg = IMSANITY_DEFAULT_PNG_TO_JPG; 173 | $data->imsanity_quality = IMSANITY_DEFAULT_QUALITY; 174 | $data->imsanity_delete_originals = false; 175 | return $data; 176 | } 177 | 178 | 179 | /** 180 | * On activation create the multisite database table if necessary. this is 181 | * called when the plugin is activated as well as when it is automatically 182 | * updated. 183 | */ 184 | function imsanity_maybe_created_custom_table() { 185 | // If not a multi-site no need to do any custom table lookups. 186 | if ( ! function_exists( 'is_multisite' ) || ( ! is_multisite() ) ) { 187 | return; 188 | } 189 | 190 | global $wpdb; 191 | 192 | $schema = imsanity_multisite_table_schema_version(); 193 | 194 | if ( '0' === $schema ) { 195 | // This is an initial database setup. 196 | $sql = 'CREATE TABLE IF NOT EXISTS ' . $wpdb->imsanity_ms . ' ( 197 | setting varchar(55), 198 | data text NOT NULL, 199 | PRIMARY KEY (setting) 200 | );'; 201 | 202 | require_once ABSPATH . 'wp-admin/includes/upgrade.php'; 203 | dbDelta( $sql ); 204 | 205 | // Add the rows to the database. 206 | $data = imsanity_get_default_multisite_settings(); 207 | $wpdb->insert( 208 | $wpdb->imsanity_ms, 209 | array( 210 | 'setting' => 'multisite', 211 | 'data' => maybe_serialize( $data ), 212 | ) 213 | ); 214 | $wpdb->insert( 215 | $wpdb->imsanity_ms, 216 | array( 217 | 'setting' => 'schema', 218 | 'data' => IMSANITY_SCHEMA_VERSION, 219 | ) 220 | ); 221 | } 222 | 223 | if ( IMSANITY_SCHEMA_VERSION !== $schema ) { 224 | // This is a schema update. for the moment there is only one schema update available, from 1.0 to 1.1. 225 | if ( '1.0' === $schema ) { 226 | // Update from version 1.0 to 1.1. 227 | $wpdb->insert( 228 | $wpdb->imsanity_ms, 229 | array( 230 | 'setting' => 'schema', 231 | 'data' => IMSANITY_SCHEMA_VERSION, 232 | ) 233 | ); 234 | $wpdb->query( "ALTER TABLE $wpdb->imsanity_ms CHANGE COLUMN data data TEXT NOT NULL;" ); 235 | } else { 236 | // @todo we don't have this yet 237 | $wpdb->update( 238 | $wpdb->imsanity_ms, 239 | array( 'data' => IMSANITY_SCHEMA_VERSION ), 240 | array( 'setting' => 'schema' ) 241 | ); 242 | } 243 | } 244 | } 245 | 246 | /** 247 | * Display the form for the multi-site settings page. 248 | */ 249 | function imsanity_network_settings() { 250 | $settings = imsanity_get_multisite_settings(); ?> 251 |
252 |

253 | 254 |
255 |

256 | EWWW Image Optimizer' 261 | ); 262 | ?> 263 |

    264 |
  • 265 |
  • 266 |
  • 267 |
  • 268 |
269 |

270 |
271 | 272 |
273 | 274 | 275 | 276 | 277 | 278 | 285 | 286 | 287 | 288 | 293 | 294 | 295 | 296 | 300 | 301 | 302 | 303 | 307 | 308 | 309 | 312 | 317 | 318 | 319 | 322 | 326 | 327 | 328 | 331 | 341 | 342 | 343 | 346 | 350 | 351 |
279 | 283 |

284 |
289 | 290 | 291 |

292 |
297 | 298 | 299 |
304 | 305 | 306 |
310 | 313 | 314 | 315 |

316 |
320 | 321 | 323 | imsanity_bmp_to_jpg ); ?> /> 324 | 325 |
329 | 330 | 332 | imsanity_png_to_jpg ); ?> /> 333 | EWWW Image Optimizer' 338 | ); 339 | ?> 340 |
344 | 345 | 347 | imsanity_delete_originals ); ?> /> 348 | 349 |
352 | 353 |

354 | 355 |
356 | 357 |
358 | imsanity_override_site = isset( $_POST['imsanity_override_site'] ) ? (bool) $_POST['imsanity_override_site'] : false; 380 | $data->imsanity_max_height = isset( $_POST['imsanity_max_height'] ) ? (int) $_POST['imsanity_max_height'] : 0; 381 | $data->imsanity_max_width = isset( $_POST['imsanity_max_width'] ) ? (int) $_POST['imsanity_max_width'] : 0; 382 | $data->imsanity_max_height_library = isset( $_POST['imsanity_max_height_library'] ) ? (int) $_POST['imsanity_max_height_library'] : 0; 383 | $data->imsanity_max_width_library = isset( $_POST['imsanity_max_width_library'] ) ? (int) $_POST['imsanity_max_width_library'] : 0; 384 | $data->imsanity_max_height_other = isset( $_POST['imsanity_max_height_other'] ) ? (int) $_POST['imsanity_max_height_other'] : 0; 385 | $data->imsanity_max_width_other = isset( $_POST['imsanity_max_width_other'] ) ? (int) $_POST['imsanity_max_width_other'] : 0; 386 | $data->imsanity_bmp_to_jpg = ! empty( $_POST['imsanity_bmp_to_jpg'] ); 387 | $data->imsanity_png_to_jpg = ! empty( $_POST['imsanity_png_to_jpg'] ); 388 | $data->imsanity_quality = isset( $_POST['imsanity_quality'] ) ? imsanity_jpg_quality( intval( $_POST['imsanity_quality'] ) ) : 82; 389 | $data->imsanity_delete_originals = ! empty( $_POST['imsanity_delete_originals'] ); 390 | 391 | $success = $wpdb->update( 392 | $wpdb->imsanity_ms, 393 | array( 'data' => maybe_serialize( $data ) ), 394 | array( 'setting' => 'multisite' ) 395 | ); 396 | 397 | // Clear the cache. 398 | $_imsanity_multisite_settings = null; 399 | add_action( 'network_admin_notices', 'imsanity_network_settings_saved' ); 400 | } 401 | 402 | /** 403 | * Display a message to inform the user the multi-site setting have been saved. 404 | */ 405 | function imsanity_network_settings_saved() { 406 | echo "

" . esc_html__( 'Imsanity network settings saved.', 'imsanity' ) . '

'; 407 | } 408 | 409 | /** 410 | * Return the multi-site settings as a standard class. If the settings are not 411 | * defined in the database or multi-site is not enabled then the default settings 412 | * are returned. This is cached so it only loads once per page load, unless 413 | * imsanity_network_settings_update is called. 414 | * 415 | * @return stdClass 416 | */ 417 | function imsanity_get_multisite_settings() { 418 | global $_imsanity_multisite_settings; 419 | $result = null; 420 | 421 | if ( ! $_imsanity_multisite_settings ) { 422 | if ( function_exists( 'is_multisite' ) && is_multisite() ) { 423 | global $wpdb; 424 | $result = $wpdb->get_var( "SELECT data FROM $wpdb->imsanity_ms WHERE setting = 'multisite'" ); 425 | } 426 | 427 | // if there's no results, return the defaults instead. 428 | $_imsanity_multisite_settings = $result 429 | ? unserialize( $result ) 430 | : imsanity_get_default_multisite_settings(); 431 | 432 | // this is for backwards compatibility. 433 | if ( ! isset( $_imsanity_multisite_settings->imsanity_max_height_library ) ) { 434 | $_imsanity_multisite_settings->imsanity_max_height_library = $_imsanity_multisite_settings->imsanity_max_height; 435 | $_imsanity_multisite_settings->imsanity_max_width_library = $_imsanity_multisite_settings->imsanity_max_width; 436 | $_imsanity_multisite_settings->imsanity_max_height_other = $_imsanity_multisite_settings->imsanity_max_height; 437 | $_imsanity_multisite_settings->imsanity_max_width_other = $_imsanity_multisite_settings->imsanity_max_width; 438 | } 439 | $_imsanity_multisite_settings->imsanity_override_site = ! empty( $_imsanity_multisite_settings->imsanity_override_site ) ? '1' : '0'; 440 | $_imsanity_multisite_settings->imsanity_bmp_to_jpg = ! empty( $_imsanity_multisite_settings->imsanity_bmp_to_jpg ) ? true : false; 441 | $_imsanity_multisite_settings->imsanity_png_to_jpg = ! empty( $_imsanity_multisite_settings->imsanity_png_to_jpg ) ? true : false; 442 | if ( ! property_exists( $_imsanity_multisite_settings, 'imsanity_delete_originals' ) ) { 443 | $_imsanity_multisite_settings->imsanity_delete_originals = false; 444 | } 445 | } 446 | return $_imsanity_multisite_settings; 447 | } 448 | 449 | /** 450 | * Gets the option setting for the given key, first checking to see if it has been 451 | * set globally for multi-site. Otherwise checking the site options. 452 | * 453 | * @param string $key The name of the option to retrieve. 454 | * @param string $ifnull Value to use if the requested option returns null. 455 | */ 456 | function imsanity_get_option( $key, $ifnull ) { 457 | $result = null; 458 | 459 | $settings = imsanity_get_multisite_settings(); 460 | 461 | if ( $settings->imsanity_override_site ) { 462 | $result = $settings->$key; 463 | if ( is_null( $result ) ) { 464 | $result = $ifnull; 465 | } 466 | } else { 467 | $result = get_option( $key, $ifnull ); 468 | } 469 | 470 | return $result; 471 | } 472 | 473 | /** 474 | * Run upgrade check for new version. 475 | */ 476 | function imsanity_upgrade() { 477 | if ( is_network_admin() ) { 478 | return; 479 | } 480 | if ( -1 === version_compare( get_option( 'imsanity_version' ), IMSANITY_VERSION ) ) { 481 | if ( wp_doing_ajax() ) { 482 | return; 483 | } 484 | imsanity_set_defaults(); 485 | update_option( 'imsanity_version', IMSANITY_VERSION ); 486 | } 487 | } 488 | 489 | /** 490 | * Set default options on multi-site. 491 | */ 492 | function imsanity_set_defaults() { 493 | $settings = imsanity_get_multisite_settings(); 494 | add_option( 'imsanity_max_width', $settings->imsanity_max_width, '', false ); 495 | add_option( 'imsanity_max_height', $settings->imsanity_max_height, '', false ); 496 | add_option( 'imsanity_max_width_library', $settings->imsanity_max_width_library, '', false ); 497 | add_option( 'imsanity_max_height_library', $settings->imsanity_max_height_library, '', false ); 498 | add_option( 'imsanity_max_width_other', $settings->imsanity_max_width_other, '', false ); 499 | add_option( 'imsanity_max_height_other', $settings->imsanity_max_height_other, '', false ); 500 | add_option( 'imsanity_bmp_to_jpg', $settings->imsanity_bmp_to_jpg, '', false ); 501 | add_option( 'imsanity_png_to_jpg', $settings->imsanity_png_to_jpg, '', false ); 502 | add_option( 'imsanity_quality', $settings->imsanity_quality, '', false ); 503 | add_option( 'imsanity_delete_originals', $settings->imsanity_delete_originals, '', false ); 504 | if ( ! get_option( 'imsanity_version' ) ) { 505 | global $wpdb; 506 | $wpdb->query( "UPDATE $wpdb->options SET autoload='no' WHERE option_name LIKE 'imsanity_%'" ); 507 | } 508 | } 509 | 510 | /** 511 | * Register the configuration settings that the plugin will use 512 | */ 513 | function imsanity_register_settings() { 514 | imsanity_upgrade(); 515 | // We only want to update if the form has been submitted. 516 | // Verification is done inside the imsanity_network_settings_update() function. 517 | if ( isset( $_POST['update_imsanity_settings'] ) && is_multisite() && is_network_admin() ) { // phpcs:ignore WordPress.Security.NonceVerification 518 | imsanity_network_settings_update(); 519 | } 520 | // Register our settings. 521 | register_setting( 'imsanity-settings-group', 'imsanity_max_height', 'intval' ); 522 | register_setting( 'imsanity-settings-group', 'imsanity_max_width', 'intval' ); 523 | register_setting( 'imsanity-settings-group', 'imsanity_max_height_library', 'intval' ); 524 | register_setting( 'imsanity-settings-group', 'imsanity_max_width_library', 'intval' ); 525 | register_setting( 'imsanity-settings-group', 'imsanity_max_height_other', 'intval' ); 526 | register_setting( 'imsanity-settings-group', 'imsanity_max_width_other', 'intval' ); 527 | register_setting( 'imsanity-settings-group', 'imsanity_bmp_to_jpg', 'boolval' ); 528 | register_setting( 'imsanity-settings-group', 'imsanity_png_to_jpg', 'boolval' ); 529 | register_setting( 'imsanity-settings-group', 'imsanity_quality', 'imsanity_jpg_quality' ); 530 | register_setting( 'imsanity-settings-group', 'imsanity_delete_originals', 'boolval' ); 531 | } 532 | 533 | /** 534 | * Validate and return the JPG quality setting. 535 | * 536 | * @param int $quality The JPG quality currently set. 537 | * @return int The (potentially) adjusted quality level. 538 | */ 539 | function imsanity_jpg_quality( $quality = null ) { 540 | if ( is_null( $quality ) ) { 541 | $quality = get_option( 'imsanity_quality' ); 542 | } 543 | if ( preg_match( '/^(100|[1-9][0-9]?)$/', $quality ) ) { 544 | return (int) $quality; 545 | } else { 546 | return IMSANITY_DEFAULT_QUALITY; 547 | } 548 | } 549 | 550 | /** 551 | * Check default WP threshold and adjust to comply with normal Imsanity behavior. 552 | * 553 | * @param int $size The default WP scaling size, or whatever has been filtered by other plugins. 554 | * @param array $imagesize { 555 | * Indexed array of the image width and height in pixels. 556 | * 557 | * @type int $0 The image width. 558 | * @type int $1 The image height. 559 | * } 560 | * @param string $file Full path to the uploaded image file. 561 | * @return int The proper size to use for scaling originals. 562 | */ 563 | function imsanity_adjust_default_threshold( $size, $imagesize = array(), $file = '' ) { 564 | if ( false !== strpos( $file, 'noresize' ) ) { 565 | return false; 566 | } 567 | $max_size = max( 568 | imsanity_get_option( 'imsanity_max_width', IMSANITY_DEFAULT_MAX_WIDTH ), 569 | imsanity_get_option( 'imsanity_max_height', IMSANITY_DEFAULT_MAX_HEIGHT ), 570 | imsanity_get_option( 'imsanity_max_width_library', IMSANITY_DEFAULT_MAX_WIDTH ), 571 | imsanity_get_option( 'imsanity_max_height_library', IMSANITY_DEFAULT_MAX_HEIGHT ), 572 | imsanity_get_option( 'imsanity_max_width_other', IMSANITY_DEFAULT_MAX_WIDTH ), 573 | imsanity_get_option( 'imsanity_max_height_other', IMSANITY_DEFAULT_MAX_HEIGHT ), 574 | (int) $size 575 | ); 576 | return $max_size; 577 | } 578 | 579 | /** 580 | * Helper function to render css styles for the settings forms 581 | * for both site and network settings page 582 | */ 583 | function imsanity_settings_css() { 584 | ?> 585 | 620 | 630 |
631 |

632 |

633 | | 634 | | 635 | 636 |

637 | 638 |
639 |

640 | EWWW Image Optimizer' 645 | ); 646 | ?> 647 |

    648 |
  • 649 |
  • 650 |
  • 651 |
  • 652 |
653 |

654 |
655 | 656 | imsanity_override_site ) { 661 | imsanity_settings_page_notice(); 662 | } else { 663 | imsanity_settings_page_form(); 664 | } 665 | 666 | ?> 667 | 668 |

669 | 670 |
671 |

672 |

673 | ' . esc_html__( 'List View in the Media Library', 'imsanity' ) . '', 678 | 'wp help imsanity resize' 679 | ); 680 | ?> 681 |

682 |
683 | 684 |
685 |

686 |

687 |
688 | ' . esc_html__( 'List View in the Media Library', 'imsanity' ) . '' 693 | ); 694 | ?> 695 |

696 |
697 | 698 | 704 | 705 |

706 | 707 |

708 | 712 | 713 |

714 |
715 | 716 | 717 | 718 |
719 | 720 | 723 | 726 | 727 | '; 730 | } 731 | 732 | /** 733 | * Multi-user config file exists so display a notice 734 | */ 735 | function imsanity_settings_page_notice() { 736 | ?> 737 |
738 |

739 |
740 |

" . esc_html__( 'The GD extension is not enabled in PHP, Imsanity may not function correctly. Enable GD or contact your web host for assistance.', 'imsanity' ) . '

'; 751 | } 752 | 753 | /** 754 | * Render the site settings form. This is processed by 755 | * WordPress built-in options persistance mechanism 756 | */ 757 | function imsanity_settings_page_form() { 758 | ?> 759 |
760 | 761 | 762 | 763 | 764 | 765 | 770 | 771 | 772 | 773 | 774 | 778 | 779 | 780 | 781 | 782 | 786 | 787 | 788 | 789 | 790 | 793 | 798 | 799 | 800 | 801 | 804 | 808 | 809 | 810 | 813 | 823 | 824 | 825 | 828 | 832 | 833 |
766 | 767 | 768 |

769 |
775 | 776 | 777 |
783 | 784 | 785 |
791 | 794 | 795 | 796 |

797 |
802 | 803 | 805 | /> 806 | 807 |
811 | 812 | 814 | /> 815 | EWWW Image Optimizer' 820 | ); 821 | ?> 822 |
826 | 827 | 829 | /> 830 | 831 |
834 | 835 |

836 | 837 |
838 | 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | 676 | Additional Copyrights 677 | 678 | Portions of the software are derived from 679 | Licenses of included software: 680 | 681 | arrive.js 682 | 683 | Copyright (c) 2014-2017 Uzair Farooq 684 | 685 | Permission is hereby granted, free of charge, to any person obtaining a copy 686 | of this software and associated documentation files (the "Software"), to deal 687 | in the Software without restriction, including without limitation the rights 688 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 689 | copies of the Software, and to permit persons to whom the Software is 690 | furnished to do so, subject to the following conditions: 691 | 692 | The above copyright notice and this permission notice shall be included in 693 | all copies or substantial portions of the Software. 694 | 695 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 696 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 697 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 698 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 699 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 700 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 701 | THE SOFTWARE. 702 | 703 | optipng 704 | 705 | Copyright (C) 2001-2017 Cosmin Truta and the Contributing Authors. 706 | For the purpose of copyright and licensing, the list of Contributing 707 | Authors is available in the accompanying AUTHORS file. 708 | 709 | This software is provided 'as-is', without any express or implied 710 | warranty. In no event will the author(s) be held liable for any damages 711 | arising from the use of this software. 712 | 713 | pngquant.c 714 | 715 | © 1989, 1991 by Jef Poskanzer. 716 | 717 | Permission to use, copy, modify, and distribute this software and its 718 | documentation for any purpose and without fee is hereby granted, provided 719 | that the above copyright notice appear in all copies and that both that 720 | copyright notice and this permission notice appear in supporting 721 | documentation. This software is provided "as is" without express or 722 | implied warranty. 723 | 724 | pngquant.c and rwpng.c/h 725 | 726 | © 1997-2002 by Greg Roelofs; based on an idea by Stefan Schneider. 727 | © 2009-2017 by Kornel Lesiński. 728 | 729 | All rights reserved. 730 | 731 | Redistribution and use in source and binary forms, with or without modification, 732 | are permitted provided that the following conditions are met: 733 | 734 | 1. Redistributions of source code must retain the above copyright notice, 735 | this list of conditions and the following disclaimer. 736 | 737 | 2. Redistributions in binary form must reproduce the above copyright notice, 738 | this list of conditions and the following disclaimer in the documentation 739 | and/or other materials provided with the distribution. 740 | 741 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 742 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 743 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 744 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 745 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 746 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 747 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 748 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 749 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 750 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 751 | 752 | WebP 753 | 754 | Copyright (c) 2010, Google Inc. All rights reserved. 755 | 756 | Redistribution and use in source and binary forms, with or without 757 | modification, are permitted provided that the following conditions are 758 | met: 759 | 760 | * Redistributions of source code must retain the above copyright 761 | notice, this list of conditions and the following disclaimer. 762 | 763 | * Redistributions in binary form must reproduce the above copyright 764 | notice, this list of conditions and the following disclaimer in 765 | the documentation and/or other materials provided with the 766 | distribution. 767 | 768 | * Neither the name of Google nor the names of its contributors may 769 | be used to endorse or promote products derived from this software 770 | without specific prior written permission. 771 | 772 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 773 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 774 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 775 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 776 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 777 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 778 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 779 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 780 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 781 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 782 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 783 | --------------------------------------------------------------------------------