skip to Main Content

When uploading large images (e.g., those with dimensions exceeding 7500 pixels), the system doesn’t automatically crop them to the custom size of 2400 pixels using the following code:

<?php
add_image_size('custom_size_2400', 2400);

Additionally, there are no restrictions on uploading images of any resolution. Currently, to achieve the desired size, you must manually crop the image to a smaller size before it will resize correctly.
To address this, there should be a setting that automatically converts the uploaded image to the maximum allowed size, after which it will resize according to the specified dimensions.

2

Answers


  1. Chosen as BEST ANSWER

    Since 5.3, WP has a limit of 2560 pixels in either direction, images above that size will not be processed by default. foliovision.com/2021/11/full-size-images-wordpress –

    Worked below code. Thanks @C3roe

    function td_big_image_size_threshold($threshold, $imagesize, $file, $attachment_id)
    {
        return 20096;
    }
    add_filter('big_image_size_threshold', 'td_big_image_size_threshold', 10, 4);
    

  2. The easiest solution, I also use it, is here. https://www.dropzone.dev/

    html

        <!DOCTYPE html>
    <html>
    
    <head>
        <title>File Upload</title>
        <link rel="stylesheet" type="text/css"
            href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.2/dropzone.min.css">
        <style>
            .dropzone .dz-preview .dz-progress {
                width: 0%;
                height: 25px;
                background-color: #4CAF50;
        margin-left: -60px;
            }
        </style>
        <link rel="stylesheet" type="text/css" href="style.css" />
        <link rel="stylesheet" type="text/css" href="form.css" />
    </head>
    
    <body>
        <div class="phppot-container tile-container text-center">
            <h2>File Upload</h2>
            <form action="upload.php" class="dropzone" id="myDropzone"></form>
        </div>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.2/min/dropzone.min.js"></script>
        <script>
            Dropzone.options.myDropzone = {
                paramName: "file", // filename handle to upload
                maxFilesize: 2, // MB
                maxFiles: 2, // number of files allowed to upload
                acceptedFiles: ".png, .jpg, .jpeg, .gif", // file types allowed to upload
             resizeWidth: 600,
              autoQueue: true,
    
                init: function () {
                    this.on("uploadprogress", function (file, progress) {
                        var progressBar = file.previewElement.querySelector(".dz-progress");
                        progressBar.style.width = progress + "%";
                        progressBar.innerHTML = progress + "%";
                    });
    
                    this.on("success", function (file, response) {
                        var progressBar = file.previewElement.querySelector(".dz-progress");
                        progressBar.classList.add("bg-success");
                        progressBar.innerHTML = "Uploaded";
                    });
    
                    this.on("error", function (file, errorMessage) {
                        var progressBar = file.previewElement.querySelector(".dz-progress");
                        progressBar.classList.add("bg-danger");
                        progressBar.innerHTML = errorMessage;
                    });
                }
            
            
            
            
            };
        </script>
    </body>
    
    </html>
    

    php code if you want to connect with mysql

        <?php
    
    if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
       $file = $_FILES['file'];
    
       // file to be uploaded to this directory
       // should have sufficient file permissions
       $uploadDir = 'uploads/';
    
       // unique file name generated for the uploaded file
       $fileName = uniqid() . '_' . $file['name'];
    
       
      require 'dbConfig.php'; 
       
       
       // moving the uploaded file from temp directory to uploads directory
       if (move_uploaded_file($file['tmp_name'], $uploadDir . $fileName)) {
           $insert = $db->query("INSERT INTO zfilestest (file_name, uploaded_on) VALUES ('".$fileName."', NOW())"); 
           echo 'File uploaded successfully.';
       } else {
           echo 'Failed to upload file.';
       }
    }
    ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search