• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

auto downsize the images without affecting the speed or the site

Abol

New member
Dec 13, 2022
9
2
3
Hey my friends
I created a marketplace with wcfm plugin, but after the vendors started to upload their photos, i found that there are images large than 30 MB in size.

is there a way or plugin to auto downsize the images without affecting the speed or the site??

thanks
 
First of all, you should restrict uploading a picture greater than a specific size like 5 MB.
Then create some custom function like this and add it into a theme or use WPCODE

Code:
function resize_uploaded_images($image_data) {
    // If the file is not an image, do not continue
    if (!getimagesize($image_data['file'])) {
        return $image_data;
    }


    $max_width = 1200;
    $max_height = 1200;


    list($original_width, $original_height) = getimagesize($image_data['file']);
    $ratio = $original_width / $original_height;


    if ($original_width > $max_width || $original_height > $max_height) {
        // Resize image
        $new_width = $max_width;
        $new_height = round($max_width / $ratio);


        if ($new_height > $max_height) {
            $new_height = $max_height;
            $new_width = round($max_height * $ratio);
        }


        $editor = wp_get_image_editor($image_data['file']);


        if (!is_wp_error($editor)) {
            $editor->resize($new_width, $new_height, true);
            $resized_file = $editor->save();


            if (!is_wp_error($resized_file)) {
                $image_data['file'] = $resized_file['path'];
                $image_data['width'] = $resized_file['width'];
                $image_data['height'] = $resized_file['height'];
            }
        }
    }
    return $image_data;
}
add_filter('wp_handle_upload_prefilter', 'resize_uploaded_images');
 
  • Like
Reactions: Abol
This will resize the image to 1200 * 1200 (change it accordingly) when a new image is uploaded. Again you should restrict image size to reduce the load on the server.
 
I understand your concern about large images affecting the speed and performance of your marketplace website. Fortunately, there are plugins available that can help you automatically downsize the images without compromising the site's speed.

Two popular options are WP Smush Pro and eWWW Image Optimizer. These plugins can optimize and compress the images upon upload, reducing their file size without sacrificing quality. By using one of these plugins, you can ensure that the images on your marketplace are optimized for web viewing, improving the overall user experience.

Give either WP Smush Pro or eWWW Image Optimizer a try, and see which one works best for your needs. They should help you automatically resize and optimize the images without affecting the speed or performance of your site.

Hope this helps! Let me know if you have any further questions.

BLOGGINGWE
 
  • Like
Reactions: Abol
First of all, you should restrict uploading a picture greater than a specific size like 5 MB.
Then create some custom function like this and add it into a theme or use WPCODE

Code:
function resize_uploaded_images($image_data) {
    // If the file is not an image, do not continue
    if (!getimagesize($image_data['file'])) {
        return $image_data;
    }


    $max_width = 1200;
    $max_height = 1200;


    list($original_width, $original_height) = getimagesize($image_data['file']);
    $ratio = $original_width / $original_height;


    if ($original_width > $max_width || $original_height > $max_height) {
        // Resize image
        $new_width = $max_width;
        $new_height = round($max_width / $ratio);


        if ($new_height > $max_height) {
            $new_height = $max_height;
            $new_width = round($max_height * $ratio);
        }


        $editor = wp_get_image_editor($image_data['file']);


        if (!is_wp_error($editor)) {
            $editor->resize($new_width, $new_height, true);
            $resized_file = $editor->save();


            if (!is_wp_error($resized_file)) {
                $image_data['file'] = $resized_file['path'];
                $image_data['width'] = $resized_file['width'];
                $image_data['height'] = $resized_file['height'];
            }
        }
    }
    return $image_data;
}
add_filter('wp_handle_upload_prefilter', 'resize_uploaded_images');
thank you very much,
But this will be for the new uploading. what about current files that are already exist in the site ???? they are about 6 GB !!! :)
 
I understand your concern about large images affecting the speed and performance of your marketplace website. Fortunately, there are plugins available that can help you automatically downsize the images without compromising the site's speed.

Two popular options are WP Smush Pro and eWWW Image Optimizer. These plugins can optimize and compress the images upon upload, reducing their file size without sacrificing quality. By using one of these plugins, you can ensure that the images on your marketplace are optimized for web viewing, improving the overall user experience.

Give either WP Smush Pro or eWWW Image Optimizer a try, and see which one works best for your needs. They should help you automatically resize and optimize the images without affecting the speed or performance of your site.

Hope this helps! Let me know if you have any further questions.

BLOGGINGWE
thanks Milan,
will these plugins work for current pix which are already uploaded to the site??? or new ones only ????
 
thanks Milan,
will these plugins work for current pix which are already uploaded to the site??? or new ones only ????

Those plugins will help you in optimising already uploaded old image files too. There is an option of bulk optimize in both the plugins. However your server (hosting) resource limit must be high in order to use bulk optimize option.
 
  • Like
Reactions: Abol
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock