output_nav(); $this->output_header(); $this->output_notice(); $this->output_review(); if (apply_filters('compressx_current_user_can', true, 'compressx-can-convert')) { $this->output_bulk_and_settings(); } if (apply_filters('compressx_current_user_can', true, 'compressx-can-use-general-settings')) { $this->output_others_settings(); } if (apply_filters('compressx_current_user_can', true, 'compressx-can-use-thumbnail-settings')) { $this->output_thumbnail_settings(); } if (apply_filters('compressx_current_user_can', true, 'compressx-can-use-exclude')) { $this->output_exclude(); } if (apply_filters('compressx_current_user_can', true, 'compressx-can-bulk-custom-convert')) { do_action("cx_output_custom_bulk"); } if (apply_filters('compressx_current_user_can', true, 'compressx-can-delete')) { $this->output_delete_images(); } $this->output_footer(); ?>
Compressx.io has successfully processed of images, and it's completely free.

test(); } else { $result = true; } if (!$result || $has_notice) { ?>

is_active_cache()) { ?>

is_apache()) { ?>

How-to: Config Apache htaccess Rules', 'compressx')) ?>

is_nginx()) { ?>

How-to: Config Nginx htaccess Rules', 'compressx')) ?>

is_litespeed()) { ?>

images
images
ajax_check_security('compressx-can-convert'); $stats = CompressX_Image_Meta_V2::get_global_stats(); $ret['result'] = 'success'; $ret['html'] = "
" . $stats['webp_converted_percent'] . "% images Outputted to WEBP
" . $stats['avif_converted_percent'] . "% images Outputted to AVIF
"; $ret['webp_saved'] = $stats['avif_saved_percent'] . '%'; $ret['avif_saved'] = $stats['webp_saved_percent'] . '%'; //webp_saved //avif_saved echo wp_json_encode($ret); die(); } public function compressx_hide_notice() { global $compressx; $compressx->ajax_check_security('compressx-can-convert'); CompressX_Options::update_option('compressx_hide_notice', true); die(); } public function compressx_rating_dismiss() { global $compressx; $compressx->ajax_check_security('compressx-can-convert'); if (isset($_POST['value'])) { $value = sanitize_text_field($_POST['value']); if ($value == 'ask_me_later') { $time = time() + 259200; CompressX_Options::update_option('compressx_rating_dismiss', $time); } if ($value == 'close') { $time = time() + 604800; CompressX_Options::update_option('compressx_rating_dismiss', $time); } else if ($value == 'already') { CompressX_Options::update_option('compressx_rating_dismiss', 0); } else if ($value == 'dismiss') { CompressX_Options::update_option('compressx_rating_dismiss', 0); } } die(); } public function delete_files() { global $compressx; $compressx->ajax_check_security('compressx-can-delete'); global $wpdb; $where['meta_key'] = "compressx_image_meta_status"; $wpdb->delete($wpdb->postmeta, $where); $where['meta_key'] = "compressx_image_meta_webp_converted"; $wpdb->delete($wpdb->postmeta, $where); $where['meta_key'] = "compressx_image_meta_avif_converted"; $wpdb->delete($wpdb->postmeta, $where); $where['meta_key'] = "compressx_image_meta_compressed"; $wpdb->delete($wpdb->postmeta, $where); $where['meta_key'] = "compressx_image_meta_og_file_size"; $wpdb->delete($wpdb->postmeta, $where); $where['meta_key'] = "compressx_image_meta_webp_converted_size"; $wpdb->delete($wpdb->postmeta, $where); $where['meta_key'] = "compressx_image_meta_avif_converted_size"; $wpdb->delete($wpdb->postmeta, $where); $where['meta_key'] = "compressx_image_meta_compressed_size"; $wpdb->delete($wpdb->postmeta, $where); $where['meta_key'] = "compressx_image_meta"; $wpdb->delete($wpdb->postmeta, $where); delete_transient('compressx_set_global_stats'); $table_name = $wpdb->prefix . "compressx_files_opt_meta"; $wpdb->get_results("TRUNCATE TABLE $table_name", ARRAY_A); CompressX_Image_Meta_V2::delete_all_image_meta(); $this->_delete_files(); $ret['result'] = "success"; echo wp_json_encode($ret); die(); } public function _delete_files() { $path = WP_CONTENT_DIR . '/compressx-nextgen'; $this->deleteDir($path); include_once COMPRESSX_DIR . '/includes/class-compressx-default-folder.php'; $dir = new CompressX_default_folder(); $dir->create_uploads_dir(); } public function deleteDir( $dirPath ) { if ( ! is_dir( $dirPath ) ) { return false; } global $wp_filesystem; if ( empty( $wp_filesystem ) ) { require_once ABSPATH . 'wp-admin/includes/file.php'; WP_Filesystem(); } if ( empty( $wp_filesystem ) ) { return false; } // Recursive delete. return $wp_filesystem->rmdir( $dirPath, true ); } public function output_bulk_and_settings() { ?>
output_convert_setting(); ?> output_bulk(); ?>
output_custom_compression_setting(); } public function output_convert_setting() { $is_auto = CompressX_Options::get_option('compressx_auto_optimize', false); if ($is_auto) { $is_auto = 'checked'; } else { $is_auto = ''; } $options = CompressX_Options::get_option('compressx_quality', array()); $quality = isset($options['quality']) ? $options['quality'] : 'lossy'; if ($quality == "lossless") { $quality_lossless = "checked"; $quality_lossy_minus = ""; $quality_lossy = ""; $quality_lossy_plus = ""; $quality_lossy_super = ""; $quality_custom = ""; $quality_custom_notice = "display:none"; } else if ($quality == "lossy_minus") { $quality_lossless = ""; $quality_lossy_minus = "checked"; $quality_lossy = ""; $quality_lossy_plus = ""; $quality_lossy_super = ""; $quality_custom = ""; $quality_custom_notice = "display:none"; } else if ($quality == "lossy") { $quality_lossless = ""; $quality_lossy_minus = ""; $quality_lossy = "checked"; $quality_lossy_plus = ""; $quality_lossy_super = ""; $quality_custom = ""; $quality_custom_notice = "display:none"; } else if ($quality == "lossy_plus") { $quality_lossless = ""; $quality_lossy_minus = ""; $quality_lossy = ""; $quality_lossy_plus = "checked"; $quality_lossy_super = ""; $quality_custom = ""; $quality_custom_notice = "display:none"; } else if ($quality == "lossy_super") { $quality_lossless = ""; $quality_lossy_minus = ""; $quality_lossy = ""; $quality_lossy_plus = ""; $quality_lossy_super = "checked"; $quality_custom = ""; $quality_custom_notice = "display:none"; } else { $quality_lossless = ""; $quality_lossy_minus = ""; $quality_lossy = ""; $quality_lossy_plus = ""; $quality_lossy_super = ""; $quality_custom = "checked"; $quality_custom_notice = ""; } if (CompressX_Image_Opt_Method::is_support_gd()) { $is_support_gd = ""; } else { $is_support_gd = "disabled"; } if (CompressX_Image_Opt_Method::is_support_imagick()) { $is_support_imagick = ""; } else { $is_support_imagick = "disabled"; } $converter_method = CompressX_Options::get_option('compressx_converter_method', false); if (empty($converter_method)) { $converter_method = CompressX_Image_Opt_Method::set_default_compress_server(); } if ($converter_method == "gd") { $gd_checked = "checked"; $imagick_checked = ""; } else if ($converter_method == "imagick") { $gd_checked = ""; $imagick_checked = "checked"; } else { $gd_checked = ""; $imagick_checked = ""; } $convert_to_webp = CompressX_Options::get_option('compressx_output_format_webp', 'not init'); if ($convert_to_webp === 'not init') { $convert_to_webp = CompressX_Image_Opt_Method::set_default_output_format_webp(); } $convert_to_avif = CompressX_Options::get_option('compressx_output_format_avif', 'not init'); if ($convert_to_avif === 'not init') { $convert_to_avif = CompressX_Image_Opt_Method::set_default_output_format_avif(); } if ($convert_to_webp) { $convert_to_webp = 'checked'; } else { $convert_to_webp = ''; } if ($convert_to_avif) { $convert_to_avif = 'checked'; } else { $convert_to_avif = ''; } if (CompressX_Image_Opt_Method::is_current_support_webp()) { $webp_support = ''; } else { $convert_to_webp = ''; $webp_support = 'disabled'; } if (CompressX_Image_Opt_Method::is_current_support_avif()) { $avif_support = ''; } else { $convert_to_avif = ''; $avif_support = 'disabled'; } $compression_level_url = admin_url() . 'admin.php?page=compression-level-compressx'; $cached = get_transient("compressx_set_global_stats"); if ($cached) { $cx_webp_saved = $cached['space_saved_webp_percent'] . '%'; $cx_avif_saved = $cached['space_saved_avif_percent'] . '%'; } else { $cx_webp_saved = '0%'; $cx_avif_saved = '0%'; } ?>
Total Savings: AVIF: | Webp:



">
> GD > Imagick
> Webp > AVIF



Watermark (Pro only)

Enable this option to automatically tag newly uploaded images, making them ready for batch watermarking. This feature allows you to easily identify and process recent uploads for watermark application, streamlining your image protection process.

Mark New Uploads for Watermarking (Pro only)

Choose the most appropriate compression level. The 5 compression levels are increasing from lossless to lossy. The default level is the Thumb, which is suitable for most situations. You can customize the compression level for WebP and AVIF formats.
Lossless: A compression level of 99
: A compression level of 90
: The default level. A compression level of 80
: A compression level of 70
Lossy: A compression level of 60
Custom: Customize the compression level

> > > > > >
Global compression level

Webp AVIF

">Advanced compression level


output_overview(); ?>
$_wp_additional_image_sizes[$size_key]['width'], 'height' => $_wp_additional_image_sizes[$size_key]['height'], 'crop' => $_wp_additional_image_sizes[$size_key]['crop'], ); if (isset($options['skip_size'][$size_key]) && $options['skip_size'][$size_key]) { $image_sizes[$size_key]['skip'] = true; } else { $image_sizes[$size_key]['skip'] = false; } } } if (! isset($sizes['medium_large']) || empty($sizes['medium_large'])) { $width = intval(get_option('medium_large_size_w')); $height = intval(get_option('medium_large_size_h')); $image_sizes['medium_large'] = array( 'width' => $width, 'height' => $height, ); if (isset($options['skip_size']['medium_large']) && $options['skip_size']['medium_large']) { $image_sizes['medium_large']['skip'] = true; } else { $image_sizes['medium_large']['skip'] = false; } } ?>
$size) { if ($showed > $max_show) { $style = "display:none"; if (!$show_more) { $show_more = true; ?> More... >

Enter the text Delete and click Go to confirm the deletion.

>

>

>

>

>

tags with tags. You can use it when .htaccess can not take effect on your server. For example, if you are not able to restart an OpenLiteSpeed server which is required for .htaccess to take effect. This method works for most browsers but does not support images in CSS.', 'compressx') ?>

>

>

You may use the options when:
1. Your image library is ImageMagick 6.x. PNG images may lose transparent background when being converted to AVIF with ImageMagick 6.x. Then you can choose not to convert PNG to AVIF. A higher ImageMagick version like 7 does not have the issue.
2. You don't want to convert PNG to WebP or AVIF because you want to keep the transparent background.

>

>

>

px px

>

Media files inside these folders will NOT be processed
  • get_children_count($exclude) . ') images') ?>
ajax_check_security('compressx-can-use-general-settings'); if (isset($_POST['setting']) && !empty($_POST['setting'])) { $json_setting = sanitize_text_field($_POST['setting']); $json_setting = stripslashes($json_setting); $setting = json_decode($json_setting, true); if (is_null($setting)) { $ret['result'] = 'failed'; $ret['error'] = 'json decode failed'; echo wp_json_encode($ret); die(); } if (isset($setting['auto_optimize'])) { if ($setting['auto_optimize'] == '1') { $options = true; } else { $options = false; } if (CompressX_Options::get_option('compressx_show_review', false) === false) { CompressX_Options::update_option('compressx_show_review', time() + 259200); } CompressX_Options::update_option('compressx_auto_optimize', $options); } if (isset($setting['convert_to_webp'])) { if ($setting['convert_to_webp'] == '1') { $options = 1; } else { $options = 0; } CompressX_Options::update_option('compressx_output_format_webp', $options); } if (isset($setting['convert_to_avif'])) { if ($setting['convert_to_avif'] == '1') { $options = 1; } else { $options = 0; } CompressX_Options::update_option('compressx_output_format_avif', $options); } if (isset($setting['quality'])) { $options['quality'] = $setting['quality']; if ($options['quality'] == "custom") { $options['quality_webp'] = isset($setting['quality_webp']) ? $setting['quality_webp'] : 80; $options['quality_avif'] = isset($setting['quality_avif']) ? $setting['quality_avif'] : 60; } CompressX_Options::update_option('compressx_quality', $options); } if (isset($setting['converter_method'])) { $converter_method = $setting['converter_method']; CompressX_Options::update_option('compressx_converter_method', $converter_method); $convert_to_webp = CompressX_Options::get_option('compressx_output_format_webp', 1); if ($convert_to_webp) { $ret['check_webp'] = true; } else { $ret['check_webp'] = false; } $convert_to_avif = CompressX_Options::get_option('compressx_output_format_avif', 1); if ($convert_to_avif) { $ret['check_avif'] = true; } else { $ret['check_avif'] = false; } if ($converter_method == 'gd') { if (CompressX_Image_Method::is_support_gd_webp()) { $ret['disable_webp'] = false; } else { $ret['disable_webp'] = true; $ret['check_webp'] = false; } if (CompressX_Image_Method::is_support_gd_avif()) { $ret['disable_avif'] = false; } else { $ret['disable_avif'] = true; $ret['check_avif'] = false; } } else if ($converter_method == 'imagick') { if (CompressX_Image_Method::is_support_imagick_webp()) { $ret['disable_webp'] = false; } else { $ret['disable_webp'] = true; $ret['check_webp'] = false; } if (CompressX_Image_Method::is_support_imagick_avif()) { $ret['disable_avif'] = false; } else { $ret['disable_avif'] = true; $ret['check_avif'] = false; } } else { $ret['disable_webp'] = true; $ret['check_webp'] = false; $ret['disable_avif'] = true; $ret['check_avif'] = false; } } /* include_once COMPRESSX_DIR . '/includes/class-compressx-webp-rewrite.php'; $rewrite=new CompressX_Webp_Rewrite(); $upload_dir = wp_upload_dir(); $rewrite->save_webp_rewrite_rule($upload_dir['basedir']); */ $ret['result'] = 'success'; echo wp_json_encode($ret); die(); } else { die(); } } public function save_others_setting() { global $compressx; $compressx->ajax_check_security('compressx-can-use-general-settings'); if (isset($_POST['setting']) && !empty($_POST['setting'])) { $json_setting = sanitize_text_field($_POST['setting']); $json_setting = stripslashes($json_setting); $setting = json_decode($json_setting, true); if (is_null($setting)) { $ret['result'] = 'failed'; $ret['error'] = 'json decode failed'; echo wp_json_encode($ret); die(); } $options = CompressX_Options::get_option('compressx_general_settings', array()); if (isset($setting['remove_exif'])) $options['remove_exif'] = $setting['remove_exif']; if (isset($setting['exclude_png'])) $options['exclude_png'] = $setting['exclude_png']; if (isset($setting['exclude_png_webp'])) $options['exclude_png_webp'] = $setting['exclude_png_webp']; // if (isset($setting['auto_remove_larger_format'])) $options['auto_remove_larger_format'] = $setting['auto_remove_larger_format']; $reset_rewrite = false; $interface_version_changed = false; if (isset($setting['disable_cache_control'])) { $reset_rewrite = true; $options['disable_cache_control'] = $setting['disable_cache_control']; } if (isset($setting['interface_version'])) { $old_interface_version = isset($options['interface_version']) ? $options['interface_version'] : 'v1'; if ($old_interface_version !== $setting['interface_version']) { $interface_version_changed = true; } $options['interface_version'] = $setting['interface_version']; } if (isset($setting['image_load'])) { if (!isset($options['image_load'])) { $options['image_load'] = 'htaccess'; } if ($options['image_load'] != $setting['image_load']) $reset_rewrite = true; $options['image_load'] = $setting['image_load']; } if (isset($setting['resize'])) $options['resize']['enable'] = $setting['resize']; if (isset($setting['resize_width'])) $options['resize']['width'] = $setting['resize_width']; if (isset($setting['resize_height'])) $options['resize']['height'] = $setting['resize_height']; if (isset($setting['converter_images_pre_request'])) $options['converter_images_pre_request'] = intval($setting['converter_images_pre_request']); // CompressX_Options::update_option('compressx_general_settings', $options); if (isset($setting['converter_method'])) { $converter_method = $setting['converter_method']; CompressX_Options::update_option('compressx_converter_method', $converter_method); } if ($options['image_load'] == 'htaccess') { if ($reset_rewrite) { include_once COMPRESSX_DIR . '/includes/class-compressx-webp-rewrite.php'; $rewrite = new CompressX_Webp_Rewrite(); $rewrite->create_rewrite_rules(); $ret['test'] = '1'; } } else if ($options['image_load'] == 'compat_htaccess') { if ($reset_rewrite) { include_once COMPRESSX_DIR . '/includes/class-compressx-webp-rewrite.php'; $rewrite = new CompressX_Webp_Rewrite(); $rewrite->create_rewrite_rules_ex(); $ret['test'] = '1'; } } else { include_once COMPRESSX_DIR . '/includes/class-compressx-webp-rewrite.php'; $rewrite = new CompressX_Webp_Rewrite(); $rewrite->remove_rewrite_rule(); } $ret['result'] = 'success'; if ($interface_version_changed) { $ret['redirect_url']=true; } else { $ret['redirect_url']=false; } echo wp_json_encode($ret); die(); } else { die(); } } public function save_size_setting() { global $compressx; $compressx->ajax_check_security('compressx-can-use-thumbnail-settings'); if (isset($_POST['setting']) && !empty($_POST['setting'])) { $json_setting = sanitize_text_field($_POST['setting']); $json_setting = stripslashes($json_setting); $setting = json_decode($json_setting, true); if (is_null($setting)) { $ret['result'] = 'failed'; $ret['error'] = 'json decode failed'; echo wp_json_encode($ret); die(); } $options = CompressX_Options::get_option('compressx_general_settings', array()); $intermediate_image_sizes = get_intermediate_image_sizes(); if (isset($setting['og'])) { $options['skip_size']['og'] = !$setting['og']; } else { $options['skip_size']['og'] = false; } foreach ($intermediate_image_sizes as $size_key) { if (isset($setting[$size_key])) { $options['skip_size'][$size_key] = !$setting[$size_key]; } else { $options['skip_size'][$size_key] = false; } } CompressX_Options::update_option('compressx_general_settings', $options); $ret['result'] = 'success'; echo wp_json_encode($ret); die(); } else { die(); } } public function get_custom_tree_dir() { global $compressx; $compressx->ajax_check_security('compressx-can-use-exclude'); try { $node_array = array(); if ($_POST['tree_node']['node']['id'] == '#') { $path = ABSPATH; if (!empty($_POST['tree_node']['path'])) { $path = sanitize_text_field($_POST['tree_node']['path']); } /* $node_array[] = array( 'text' => basename($path), 'children' => true, 'id' => $path, 'icon' => 'dashicons dashicons-category cx-icon-color-yellow', 'state' => array( 'opened' => true ) );*/ } else { $path = sanitize_text_field($_POST['tree_node']['node']['id']); } $upload_dir = wp_upload_dir(); $uploads_path = $upload_dir['basedir']; $uploads_path = str_replace('\\', '/', $uploads_path); $uploads_path = $uploads_path . '/'; if ($path == $uploads_path) { $init = true; $key = gmdate('Y', time()); } else { $init = false; $key = gmdate('Y', time()); } $path = trailingslashit(str_replace('\\', '/', realpath($path))); if ($dh = opendir($path)) { while (substr($path, -1) == '/') { $path = rtrim($path, '/'); } $skip_paths = array(".", ".."); while (($value = readdir($dh)) !== false) { trailingslashit(str_replace('\\', '/', $value)); if (!in_array($value, $skip_paths)) { if (is_dir($path . '/' . $value)) { $node['children'] = $this->has_children($path . '/' . $value); $node['id'] = $path . '/' . $value; if ($init) { if ($value == $key) { $node['state']['opened'] = true; } } // $node['icon'] = 'dashicons dashicons-open-folder cx-icon-color-techblue compressx-text'; $node['children_count'] = $this->get_children_count($path . '/' . $value); $node['text'] = $value . ',(' . $node['children_count'] . ') images'; $node['text'] .= ''; $node_array[] = $node; /* if($this->is_media_folder($path . '/' . $value)) { $node['children'] = $this->has_children($path . '/' . $value); $node['id'] = $path . '/' . $value; if($init) { if($value==$key) { $node['state']['opened']=true; } } // $node['icon'] = 'dashicons dashicons-open-folder cx-icon-color-techblue compressx-text'; $node['children_count']=$this->get_children_count($path . '/' . $value); $node['text'] = $value.',('. $node['children_count'].') images'; $node['text'] .=''; $node_array[] = $node; } else { continue; }*/ } else { //$node['text'] = $value; //$node['children'] = true; //$node['id'] = $path . '/' . $value; //$node['icon'] = 'dashicons dashicons-media-default cx-icon-color-yellow'; //$node_array[] = $node; continue; } } } } $ret['nodes'] = $node_array; echo wp_json_encode($ret); } catch (Exception $error) { $message = 'An exception has occurred. class: ' . get_class($error) . ';msg: ' . $error->getMessage() . ';code: ' . $error->getCode() . ';line: ' . $error->getLine() . ';in_file: ' . $error->getFile() . ';'; //error_log($message); echo wp_json_encode(array('result' => 'failed', 'error' => $message)); } die(); } public function has_children($path) { if ($dh = opendir($path)) { while (substr($path, -1) == '/') { $path = rtrim($path, '/'); } $skip_paths = array(".", ".."); while (($value = readdir($dh)) !== false) { trailingslashit(str_replace('\\', '/', $value)); if (!in_array($value, $skip_paths)) { if (is_dir($path . '/' . $value)) { return true; } } } } return false; } public function is_media_folder($path) { $upload_dir = wp_upload_dir(); $base_dir = $upload_dir['basedir']; $base_dir = trailingslashit(str_replace('\\', '/', realpath($base_dir))); $path = str_replace($base_dir, '', $path); $path_arr = explode('/', $path); if (count($path_arr) >= 1) { if (is_numeric($path_arr[0]) && $path_arr[0] > 1950 && $path_arr[0] < 2050) { return true; } } return false; } public function get_children_count($path) { try { $rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); $files = 0; /** @var SplFileInfo $file */ foreach ($rii as $file) { if ($file->isDir()) { continue; } $files++; } return $files; } catch (Exception $e) { return 0; } } public function add_exclude_folders() { global $compressx; $compressx->ajax_check_security('compressx-can-use-exclude'); $json_excludes = sanitize_text_field($_POST['excludes']); $json_excludes = stripslashes($json_excludes); $new_excludes = json_decode($json_excludes, true); CompressX_Options::update_option('compressx_media_excludes', $new_excludes); $abs_path = trailingslashit(str_replace('\\', '/', realpath(ABSPATH))); $html = '