0

Is there a way to limit the dimensions of the full size uploaded image (made normally through the Media library)?

I have clients that upload huge images files with resolutions sometimes greater than 5000 x 5000. They don't quite understand why Wordpress/websites have a hard time with these images.

Limiting "Full" size images seems like a great solution. Is it possible via functions.php?

5
  • I know there is a way to do this as I've seen some Plugins that allow this feature, I will have a look into it if no one gives you an answer
    – Stephen
    Jan 26, 2016 at 19:14
  • I'd love to do it manually, but I've just discovered this plugin: wordpress.org/plugins/imsanity Jan 26, 2016 at 19:14
  • I have the solutions I think, I will post it
    – Stephen
    Jan 26, 2016 at 19:15
  • We have used info from this codex page to set img sizes for media (although you set them also in the back-end in Settings/Media ) and used this wpse answer to keep the folder on the server 'clean and uncluttered'. For us it works like a charm and the client is also satisfied with the results.
    – Charles
    Jan 26, 2016 at 19:38
  • 1
    Imsanity plugin is good for sure, but if you want to do handle both image optimization and size limiting, I find wordpress.org/plugins/ewww-image-optimizer is a better option now they recently also added image resizing functionality.
    – Trevor
    May 18, 2016 at 1:46

2 Answers 2

2

So I've found this WP_Image_Editor in the CodeX. Basically by adding the code below it should automatically resize an image :)

Code:

$image = wp_get_image_editor( 'cool_image.jpg' ); // Return an implementation that extends WP_Image_Editor

if ( ! is_wp_error( $image ) ) {
    $image->resize( 300, 300, true );
    $image->save( 'new_image.jpg' );
}

I don't know exactly if this will work but I'm sure if you look in the link I've gave you then you should be able to find it there.

Best of luck :)

0

I have found this in quora , if anyone has any other method to resize especially old uploaded images ,

add_filter('wp_generate_attachment_metadata','ad_limit_media_file_max_size'); 
function ad_limit_media_file_max_size($image_data) { 
    if (!isset($image_data['sizes']['large'])) return $image_data; 
    $upload_dir = wp_upload_dir(); 
    $uploaded_image_location = $upload_dir['basedir'] . '/' .$image_data['file']; 
    $current_subdir = substr($image_data['file'],0,strrpos($image_data['file'],"/")); 
    $large_image_location = $upload_dir['basedir'] . '/'.$current_subdir.'/'.$image_data['sizes']['large']['file']; 
    unlink($uploaded_image_location); 
    rename($large_image_location,$uploaded_image_location); 
    $image_data['width'] = $image_data['sizes']['large']['width']; 
    $image_data['height'] = $image_data['sizes']['large']['height']; 
    unset($image_data['sizes']['large']); 
    return $image_data; 
} 

Quora link: https://www.quora.com/Is-it-possible-to-create-a-child-theme-in-WordPress-that-loads-faster-than-its-parent Good luck

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.