resize( $width, $height, $crop ) ) ) return false; $resized_file = $editor->save(); if ( ! is_wp_error( $resized_file ) ) { $resized_rel_path = str_replace( $upload_dir, '', $resized_file['path'] ); $img_url = $upload_url . $resized_rel_path; } else { return false; } } } if ( true === $upscale ) remove_filter( 'image_resize_dimensions', array( $this, 'aq_upscale' ) ); if ( $single ) { $image = $img_url; } else { $image = array ( 0 => $img_url, 1 => $dst_w, 2 => $dst_h ); } return $image; } /** * Callback to overwrite WP computing of thumbnail measures */ function aq_upscale( $default, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) { if ( ! $crop ) return null; // Let the wordpress default function handle this. // Here is the point we allow to use larger image size than the original one. $aspect_ratio = $orig_w / $orig_h; $new_w = $dest_w; $new_h = $dest_h; if ( ! $new_w ) { $new_w = intval( $new_h * $aspect_ratio ); } if ( ! $new_h ) { $new_h = intval( $new_w / $aspect_ratio ); } $size_ratio = max( $new_w / $orig_w, $new_h / $orig_h ); $crop_w = round( $new_w / $size_ratio ); $crop_h = round( $new_h / $size_ratio ); $s_x = floor( ( $orig_w - $crop_w ) / 2 ); $s_y = floor( ( $orig_h - $crop_h ) / 2 ); return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h ); } } } if(!function_exists('rev_aq_resize')) { /** * This is just a tiny wrapper function for the class above so that there is no * need to change any code in your own WP themes. Usage is still the same :) */ // function rev_aq_resize_custom( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) { // // $aq_resize = Rev_Aq_Resize::getInstance(); // // return $aq_resize->process( $url, $width, $height, $crop, $single, $upscale ); // if($width<300){ // $width = 300; // } // if($height<200){ // $width = 200; // } // $name = basename($url); // $extension = pathinfo($url, PATHINFO_EXTENSION); // $only_file_name = pathinfo($url,PATHINFO_FILENAME); // $image_url = $url; // $image_dir = RevSliderFunctionsWP::getImageDirFromUrl($url); // // $image_url_without_name = str_replace($name, '', $image_url); // $image_dir_without_name = str_replace($name, '', $image_dir); // // $new_image_dir = $image_dir_without_name.$only_file_name.'-'.$width.'x'.$height.'.'.$extension; // $new_image_url = $image_url_without_name.$only_file_name.'-'.$width.'x'.$height.'.'.$extension; // // if(!file_exists($new_image_dir)){ // $res_img = new ImageToolsHelper(); // $res_img->resize($image_dir,$new_image_dir, $width, $height); // } // // if(file_exists($new_image_dir)){ // return $new_image_url; // } // // } // function rev_aq_resize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) { $aq_resize = Rev_Aq_Resize::getInstance(); return $aq_resize->process( $url, $width, $height, $crop, $single, $upscale ); } }